spring 依赖注入方式出现的问题:必须为元素类型 "constructor-arg" 声明属性 "name"。
2019-07-05 19:36
169 查看
版权声明:本文为博主原创文章,遵循 CC 4.0 by-sa 版权协议,转载请附上原文出处链接和本声明。
本文链接:https://blog.csdn.net/qq_39944559/article/details/94740735
spring 依赖注入方式出现的问题:必须为元素类型 “constructor-arg” 声明属性 “name”。
我的bean.xml头文件:
<?xml version="1.0" encoding="utf-8"?> <!DOCTYPE beans PUBLIC "-//SPRING//DTD BEAN 2.0//EN" "http://www.springframework.org/dtd/spring-beans-2.0.dtd">
修改为
<?xml version="1.0" encoding="UTF-8"?> <beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:p="http://www.springframework.org/schema/p" xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd">
我在这里出现以下错误
: org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'accountService' defined in class path resource [bean.xml]: Unsatisfied dependency expressed through constructor parameter 2: Could not convert argument value of type [java.lang.String] to required type [java.util.Date]: Failed to convert value of type 'java.lang.String' to required type 'java.util.Date'; nested exception is java.lang.IllegalStateException: Cannot convert value of type 'java.lang.String' to required type 'java.util.Date': no matching editors or conversion strategy found Exception in thread "main" org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'accountService' defined in class path resource [bean.xml]: Unsatisfied dependency expressed through constructor parameter 2: Could not convert argument value of type [java.lang.String] to required type [java.util.Date]: Failed to convert value of type 'java.lang.String' to required type 'java.util.Date'; nested exception is java.lang.IllegalStateException: Cannot convert value of type 'java.lang.String' to required type 'java.util.Date': no matching editors or conversion strategy found a
解决:
<constructor-arg name="birthday" ref="now"> </constructor-arg> <!-- 配置一个日期对象--> <bean id="now" class="java.util.Date"></bean>
相关文章推荐
- 报错:spring属性注入时<constructor-arg>标签不可出现属性“name”,这是什么原因呢?
- 错误: 必须为元素类型 "interceptors" 声明属性 "name"
- 使用spring注解方式实现组件的声明,并且用注解注入方式解决依赖关系
- Spring依赖注入的三种方式详解之一:属性注入
- Spring依赖注入的三种方式详解之一:属性注入
- 使用spring的aop对Struts2的Action拦截后出现依赖注入为空问题
- SpringBoot集成Quartz(解决@Autowired空指针Null问题即依赖注入的属性为null)
- (4) 编码剖析Spring装配基本属性的原理【附加:注入依赖对象的两种方式】
- websphere6.1部署SystemErr.log必须为元素类型“web-app”声明属性“ve
- 解决websphere6.1必须为元素类型web-app声明属性version
- 必须为元素类型 "mapper" 声明属性 "namespace" 或The content of element type "mapper" must match "EMPTY"
- PHP类中声明数组类型属性出现的问题
- spring入门(依赖注入方式,生命周期,读取属性文件值,数据库接连)
- spring依赖注入方式一:属性注入
- 出现严重: Parse Fatal Error at line 147 column 125: 元素类型 "Resource" 必须后跟属性规范 ">的原因" 或 "/>"。
- 有一个NSStirng类型,retain方式声明的name属性的setter方法内部每一行代码的作用?
- spring 学习之 bean 的注入方式 property和constructor-arg的使用方式
- Spring Boot+Thymeleaf出现org.xml.sax.SAXParseException: 元素类型 "meta" 必须由匹配的结束标记 "</meta>" 终止。
- spring按类型进行依赖注入引起的问题
- 使用spring的aop实现权限拦截后出现依赖注入为空的问题