D:\jdk\jdk8\bin\java.exe -ea -Didea.test.cyclic.buffer.size=1048576 "-javaagent:D:\worksoft\IntelliJ IDEA 2021.3.3\lib\idea_rt.jar=4574:D:\worksoft\IntelliJ IDEA 2021.3.3\bin" -Dfile.encoding=UTF-8 -classpath "D:\worksoft\IntelliJ IDEA 2021.3.3\lib\idea_rt.jar;D:\worksoft\IntelliJ IDEA 2021.3.3\plugins\junit\lib\junit5-rt.jar;D:\worksoft\IntelliJ IDEA 2021.3.3\plugins\junit\lib\junit-rt.jar;D:\jdk\jdk8\jre\lib\charsets.jar;D:\jdk\jdk8\jre\lib\ext\access-bridge-64.jar;D:\jdk\jdk8\jre\lib\ext\cldrdata.jar;D:\jdk\jdk8\jre\lib\ext\dnsns.jar;D:\jdk\jdk8\jre\lib\ext\jaccess.jar;D:\jdk\jdk8\jre\lib\ext\jfxrt.jar;D:\jdk\jdk8\jre\lib\ext\localedata.jar;D:\jdk\jdk8\jre\lib\ext\nashorn.jar;D:\jdk\jdk8\jre\lib\ext\sunec.jar;D:\jdk\jdk8\jre\lib\ext\sunjce_provider.jar;D:\jdk\jdk8\jre\lib\ext\sunmscapi.jar;D:\jdk\jdk8\jre\lib\ext\sunpkcs11.jar;D:\jdk\jdk8\jre\lib\ext\zipfs.jar;D:\jdk\jdk8\jre\lib\jce.jar;D:\jdk\jdk8\jre\lib\jfr.jar;D:\jdk\jdk8\jre\lib\jfxswt.jar;D:\jdk\jdk8\jre\lib\jsse.jar;D:\jdk\jdk8\jre\lib\management-agent.jar;D:\jdk\jdk8\jre\lib\resources.jar;D:\jdk\jdk8\jre\lib\rt.jar;E:\java\spring--study\spring-05-Autowire\target\test-classes;E:\java\spring--study\spring-05-Autowire\target\classes;D:\Maven\maven-repository\org\springframework\spring-webmvc\5.3.20\spring-webmvc-5.3.20.jar;D:\Maven\maven-repository\org\springframework\spring-aop\5.3.20\spring-aop-5.3.20.jar;D:\Maven\maven-repository\org\springframework\spring-beans\5.3.20\spring-beans-5.3.20.jar;D:\Maven\maven-repository\org\springframework\spring-context\5.3.20\spring-context-5.3.20.jar;D:\Maven\maven-repository\org\springframework\spring-core\5.3.20\spring-core-5.3.20.jar;D:\Maven\maven-repository\org\springframework\spring-jcl\5.3.20\spring-jcl-5.3.20.jar;D:\Maven\maven-repository\org\springframework\spring-expression\5.3.20\spring-expression-5.3.20.jar;D:\Maven\maven-repository\org\springframework\spring-web\5.3.20\spring-web-5.3.20.jar;D:\Maven\maven-repository\junit\junit\4.12\junit-4.12.jar;D:\Maven\maven-repository\org\hamcrest\hamcrest-core\1.3\hamcrest-core-1.3.jar" com.intellij.rt.junit.JUnitStarter -ideVersion5 -junit4 MyTest,test
七月 06, 2022 2:35:36 下午 org.springframework.context.support.AbstractApplicationContext refresh
警告: Exception encountered during context initialization - cancelling refresh attempt: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'people' defined in class path resource [beans.xml]: Initialization of bean failed; nested exception is org.springframework.beans.ConversionNotSupportedException: Failed to convert property value of type 'java.lang.String' to required type 'com.sqt.pojo.Cat' for property 'cat'; nested exception is java.lang.IllegalStateException: Cannot convert value of type 'java.lang.String' to required type 'com.sqt.pojo.Cat' for property 'cat': no matching editors or conversion strategy found
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'people' defined in class path resource [beans.xml]: Initialization of bean failed; nested exception is org.springframework.beans.ConversionNotSupportedException: Failed to convert property value of type 'java.lang.String' to required type 'com.sqt.pojo.Cat' for property 'cat'; nested exception is java.lang.IllegalStateException: Cannot convert value of type 'java.lang.String' to required type 'com.sqt.pojo.Cat' for property 'cat': no matching editors or conversion strategy found
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:628)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:542)
at org.springframework.beans.factory.support.AbstractBeanFactory.lambda$doGetBean$0(AbstractBeanFactory.java:335)
at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:234)
at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:333)
at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:208)
at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:953)
at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:918)
at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:583)
at org.springframework.context.support.ClassPathXmlApplicationContext.<init>(ClassPathXmlApplicationContext.java:144)
at org.springframework.context.support.ClassPathXmlApplicationContext.<init>(ClassPathXmlApplicationContext.java:85)
at MyTest.test(MyTest.java:8)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:50)
at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12)
at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:47)
at org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:17)
at org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:325)
at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:78)
at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:57)
at org.junit.runners.ParentRunner$3.run(ParentRunner.java:290)
at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:71)
at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:288)
at org.junit.runners.ParentRunner.access$000(ParentRunner.java:58)
at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:268)
at org.junit.runners.ParentRunner.run(ParentRunner.java:363)
at org.junit.runner.JUnitCore.run(JUnitCore.java:137)
at com.intellij.junit4.JUnit4IdeaTestRunner.startRunnerWithArgs(JUnit4IdeaTestRunner.java:69)
at com.intellij.rt.junit.IdeaTestRunner$Repeater$1.execute(IdeaTestRunner.java:38)
at com.intellij.rt.execution.junit.TestsRepeater.repeat(TestsRepeater.java:11)
at com.intellij.rt.junit.IdeaTestRunner$Repeater.startRunnerWithArgs(IdeaTestRunner.java:35)
at com.intellij.rt.junit.JUnitStarter.prepareStreamsAndStart(JUnitStarter.java:235)
at com.intellij.rt.junit.JUnitStarter.main(JUnitStarter.java:54)
Caused by: org.springframework.beans.ConversionNotSupportedException: Failed to convert property value of type 'java.lang.String' to required type 'com.sqt.pojo.Cat' for property 'cat'; nested exception is java.lang.IllegalStateException: Cannot convert value of type 'java.lang.String' to required type 'com.sqt.pojo.Cat' for property 'cat': no matching editors or conversion strategy found
at org.springframework.beans.AbstractNestablePropertyAccessor.convertIfNecessary(AbstractNestablePropertyAccessor.java:595)
at org.springframework.beans.AbstractNestablePropertyAccessor.convertForProperty(AbstractNestablePropertyAccessor.java:609)
at org.springframework.beans.BeanWrapperImpl.convertForProperty(BeanWrapperImpl.java:219)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.convertForProperty(AbstractAutowireCapableBeanFactory.java:1756)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.applyPropertyValues(AbstractAutowireCapableBeanFactory.java:1712)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean(AbstractAutowireCapableBeanFactory.java:1452)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:619)
... 35 more
Caused by: java.lang.IllegalStateException: Cannot convert value of type 'java.lang.String' to required type 'com.sqt.pojo.Cat' for property 'cat': no matching editors or conversion strategy found
at org.springframework.beans.TypeConverterDelegate.convertIfNecessary(TypeConverterDelegate.java:262)
at org.springframework.beans.AbstractNestablePropertyAccessor.convertIfNecessary(AbstractNestablePropertyAccessor.java:590)
... 41 more
进程已结束,退出代码-1
报错信息
解决
<bean id="cat" class="com.sqt.pojo.Cat"/>
<bean id="dog" class="com.sqt.pojo.Dog"/>
<bean id="people" class="com.sqt.pojo.People">
<property name="name" value="撒旦法"/>
<!-- 报错,people初始化失败,这里不是赋值而是指向cat和dog的beans对象-->
<!-- <property name="cat" value="黑猫"/>-->
<!-- <property name="dog" value="白狗"/>-->
<property name="cat" ref="cat"/>
<property name="dog" ref="dog"/>
</bean>