Bonjour,

débutant en spring, j'ai un soucis pour faire ma configuration.

Mes xml sont comme ceci:
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
<?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:context="http://www.springframework.org/schema/context"
    xmlns:util="http://www.springframework.org/schema/util"
    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
        http://www.springframework.org/schema/util http://www.springframework.org/schema/util/spring-util-3.0.xsd
        http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.0.xsd">
 
 
    <util:properties id="config">
      <prop key="statusDb.driver">org.h2.Driver</prop>
      <prop key="statusDb.url">jdbc:h2:mem:test;DB_CLOSE_DELAY=-1</prop>
      <prop key="statusDb.user">sa</prop>
      <prop key="statusDb.password">sa</prop>
    </util:properties>
 
    <context:property-placeholder properties-ref="config"/>
</beans>
et ceci
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
<?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:context="http://www.springframework.org/schema/context"
    xmlns:util="http://www.springframework.org/schema/util" 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
        http://www.springframework.org/schema/util http://www.springframework.org/schema/util/spring-util-3.0.xsd
        http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.0.xsd">
 
 
    <bean id="persistentDataSource" class="org.apache.commons.dbcp.BasicDataSource"
        destroy-method="close">
        <property name="driverClassName"><value>${statusDb.driver}</value></property>
        <property name="url"><value>${statusDb.url}</value></property>
        <property name="username"><value>${statusDb.user}</value></property>
        <property name="password"><value>${statusDb.password}</value></property>
    </bean>
    <bean id="DbLogging" name="LogStatusAppender"
        class="xxx.ProductStatusAppender">
        <property name="datasource">
          <idref local="persistentDataSource"/>
        </property>
        </bean>
</beans>
Lorsque je charge ce context avec spring 3, j'ai cette erreur:
Cannot convert value of type [java.lang.String] to required type [javax.sql.DataSource]

console:
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
2010-10-22 16:29:17 ClassPathXmlApplicationContext [INFO] Refreshing org.springframework.context.support.ClassPathXmlApplicationContext@3d358f03: startup date [Fri Oct 22 16:29:17 CEST 2010]; root of context hierarchy
2010-10-22 16:29:17 XmlBeanDefinitionReader [INFO] Loading XML bean definitions from class path resource [contexts/testNg-database.xml]
2010-10-22 16:29:17 DefaultDocumentLoader [DEBUG] Using JAXP provider [com.sun.org.apache.xerces.internal.jaxp.DocumentBuilderFactoryImpl]
2010-10-22 16:29:18 PluggableSchemaResolver [DEBUG] Loading schema mappings from [META-INF/spring.schemas]
2010-10-22 16:29:18 PluggableSchemaResolver [DEBUG] Loaded schema mappings: {http://www.springframework.org/schema/lang/spring-lang.xsd=org/springframework/scripting/config/spring-lang-3.0.xsd, http://www.springframework.org/schema/lang/spring-lang-2.5.xsd=org/springframework/scripting/config/spring-lang-2.5.xsd, http://www.springframework.org/schema/context/spring-context-2.5.xsd=org/springframework/context/config/spring-context-2.5.xsd, http://www.springframework.org/schema/aop/spring-aop.xsd=org/springframework/aop/config/spring-aop-3.0.xsd, http://www.springframework.org/schema/context/spring-context.xsd=org/springframework/context/config/spring-context-3.0.xsd, http://www.springframework.org/schema/util/spring-util-3.0.xsd=org/springframework/beans/factory/xml/spring-util-3.0.xsd, http://www.springframework.org/schema/util/spring-util-2.0.xsd=org/springframework/beans/factory/xml/spring-util-2.0.xsd, http://www.springframework.org/schema/task/spring-task-3.0.xsd=org/springframework/scheduling/config/spring-task-3.0.xsd, http://www.springframework.org/schema/util/spring-util-2.5.xsd=org/springframework/beans/factory/xml/spring-util-2.5.xsd, http://www.springframework.org/schema/tool/spring-tool-3.0.xsd=org/springframework/beans/factory/xml/spring-tool-3.0.xsd, http://www.springframework.org/schema/tool/spring-tool-2.0.xsd=org/springframework/beans/factory/xml/spring-tool-2.0.xsd, http://www.springframework.org/schema/task/spring-task.xsd=org/springframework/scheduling/config/spring-task-3.0.xsd, http://www.springframework.org/schema/context/spring-context-3.0.xsd=org/springframework/context/config/spring-context-3.0.xsd, http://www.springframework.org/schema/beans/spring-beans-2.0.xsd=org/springframework/beans/factory/xml/spring-beans-2.0.xsd, http://www.springframework.org/schema/tool/spring-tool-2.5.xsd=org/springframework/beans/factory/xml/spring-tool-2.5.xsd, http://www.springframework.org/schema/jee/spring-jee.xsd=org/springframework/ejb/config/spring-jee-3.0.xsd, http://www.springframework.org/schema/beans/spring-beans-2.5.xsd=org/springframework/beans/factory/xml/spring-beans-2.5.xsd, http://www.springframework.org/schema/beans/spring-beans.xsd=org/springframework/beans/factory/xml/spring-beans-3.0.xsd, http://www.springframework.org/schema/tool/spring-tool.xsd=org/springframework/beans/factory/xml/spring-tool-3.0.xsd, http://www.springframework.org/schema/aop/spring-aop-3.0.xsd=org/springframework/aop/config/spring-aop-3.0.xsd, http://www.springframework.org/schema/jee/spring-jee-3.0.xsd=org/springframework/ejb/config/spring-jee-3.0.xsd, http://www.springframework.org/schema/aop/spring-aop-2.0.xsd=org/springframework/aop/config/spring-aop-2.0.xsd, http://www.springframework.org/schema/jee/spring-jee-2.0.xsd=org/springframework/ejb/config/spring-jee-2.0.xsd, http://www.springframework.org/schema/aop/spring-aop-2.5.xsd=org/springframework/aop/config/spring-aop-2.5.xsd, http://www.springframework.org/schema/jee/spring-jee-2.5.xsd=org/springframework/ejb/config/spring-jee-2.5.xsd, http://www.springframework.org/schema/beans/spring-beans-3.0.xsd=org/springframework/beans/factory/xml/spring-beans-3.0.xsd, http://www.springframework.org/schema/lang/spring-lang-3.0.xsd=org/springframework/scripting/config/spring-lang-3.0.xsd, http://www.springframework.org/schema/lang/spring-lang-2.0.xsd=org/springframework/scripting/config/spring-lang-2.0.xsd, http://www.springframework.org/schema/util/spring-util.xsd=org/springframework/beans/factory/xml/spring-util-3.0.xsd}
2010-10-22 16:29:18 PluggableSchemaResolver [DEBUG] Found XML schema [http://www.springframework.org/schema/beans/spring-beans-3.0.xsd] in classpath: org/springframework/beans/factory/xml/spring-beans-3.0.xsd
2010-10-22 16:29:18 PluggableSchemaResolver [DEBUG] Found XML schema [http://www.springframework.org/schema/util/spring-util-3.0.xsd] in classpath: org/springframework/beans/factory/xml/spring-util-3.0.xsd
2010-10-22 16:29:18 PluggableSchemaResolver [DEBUG] Found XML schema [http://www.springframework.org/schema/tool/spring-tool-3.0.xsd] in classpath: org/springframework/beans/factory/xml/spring-tool-3.0.xsd
2010-10-22 16:29:18 PluggableSchemaResolver [DEBUG] Found XML schema [http://www.springframework.org/schema/context/spring-context-3.0.xsd] in classpath: org/springframework/context/config/spring-context-3.0.xsd
2010-10-22 16:29:18 DefaultBeanDefinitionDocumentReader [DEBUG] Loading bean definitions
2010-10-22 16:29:18 DefaultNamespaceHandlerResolver [DEBUG] Loaded NamespaceHandler mappings: {http://www.springframework.org/schema/p=org.springframework.beans.factory.xml.SimplePropertyNamespaceHandler, http://www.springframework.org/schema/lang=org.springframework.scripting.config.LangNamespaceHandler, http://www.springframework.org/schema/jee=org.springframework.ejb.config.JeeNamespaceHandler, http://www.springframework.org/schema/aop=org.springframework.aop.config.AopNamespaceHandler, http://www.springframework.org/schema/util=org.springframework.beans.factory.xml.UtilNamespaceHandler, http://www.springframework.org/schema/task=org.springframework.scheduling.config.TaskNamespaceHandler, http://www.springframework.org/schema/context=org.springframework.context.config.ContextNamespaceHandler}
2010-10-22 16:29:18 XmlBeanDefinitionReader [DEBUG] Loaded 2 bean definitions from location pattern [/contexts/testNg-database.xml]
2010-10-22 16:29:18 XmlBeanDefinitionReader [INFO] Loading XML bean definitions from class path resource [beans-config.xml]
2010-10-22 16:29:18 DefaultDocumentLoader [DEBUG] Using JAXP provider [com.sun.org.apache.xerces.internal.jaxp.DocumentBuilderFactoryImpl]
2010-10-22 16:29:18 PluggableSchemaResolver [DEBUG] Found XML schema [http://www.springframework.org/schema/beans/spring-beans-3.0.xsd] in classpath: org/springframework/beans/factory/xml/spring-beans-3.0.xsd
2010-10-22 16:29:18 DefaultBeanDefinitionDocumentReader [DEBUG] Loading bean definitions
2010-10-22 16:29:18 XmlBeanDefinitionReader [DEBUG] Loaded 3 bean definitions from location pattern [/beans-config.xml]
2010-10-22 16:29:18 ClassPathXmlApplicationContext [DEBUG] Bean factory for org.springframework.context.support.ClassPathXmlApplicationContext@3d358f03: org.springframework.beans.factory.support.DefaultListableBeanFactory@1b45e2d5: defining beans [config,org.springframework.beans.factory.config.PropertyPlaceholderConfigurer#0,persistentDataSource,DbLogging,main]; root of factory hierarchy
2010-10-22 16:29:18 DefaultListableBeanFactory [DEBUG] Creating shared instance of singleton bean 'org.springframework.beans.factory.config.PropertyPlaceholderConfigurer#0'
2010-10-22 16:29:18 DefaultListableBeanFactory [DEBUG] Creating instance of bean 'org.springframework.beans.factory.config.PropertyPlaceholderConfigurer#0'
2010-10-22 16:29:18 DefaultListableBeanFactory [DEBUG] Eagerly caching bean 'org.springframework.beans.factory.config.PropertyPlaceholderConfigurer#0' to allow for resolving potential circular references
2010-10-22 16:29:18 DefaultListableBeanFactory [DEBUG] Creating shared instance of singleton bean 'config'
2010-10-22 16:29:18 DefaultListableBeanFactory [DEBUG] Creating instance of bean 'config'
2010-10-22 16:29:18 DefaultListableBeanFactory [DEBUG] Eagerly caching bean 'config' to allow for resolving potential circular references
2010-10-22 16:29:18 DefaultListableBeanFactory [DEBUG] Invoking afterPropertiesSet() on bean with name 'config'
2010-10-22 16:29:18 DefaultListableBeanFactory [DEBUG] Finished creating instance of bean 'config'
2010-10-22 16:29:18 DefaultListableBeanFactory [DEBUG] Finished creating instance of bean 'org.springframework.beans.factory.config.PropertyPlaceholderConfigurer#0'
2010-10-22 16:29:18 ClassPathXmlApplicationContext [DEBUG] Unable to locate MessageSource with name 'messageSource': using default [org.springframework.context.support.DelegatingMessageSource@293bdd36]
2010-10-22 16:29:18 ClassPathXmlApplicationContext [DEBUG] Unable to locate ApplicationEventMulticaster with name 'applicationEventMulticaster': using default [org.springframework.context.event.SimpleApplicationEventMulticaster@51701bdc]
2010-10-22 16:29:18 DefaultListableBeanFactory [INFO] Pre-instantiating singletons in org.springframework.beans.factory.support.DefaultListableBeanFactory@1b45e2d5: defining beans [config,org.springframework.beans.factory.config.PropertyPlaceholderConfigurer#0,persistentDataSource,DbLogging,main]; root of factory hierarchy
2010-10-22 16:29:18 DefaultListableBeanFactory [DEBUG] Returning cached instance of singleton bean 'config'
2010-10-22 16:29:18 DefaultListableBeanFactory [DEBUG] Returning cached instance of singleton bean 'org.springframework.beans.factory.config.PropertyPlaceholderConfigurer#0'
2010-10-22 16:29:18 DefaultListableBeanFactory [DEBUG] Creating shared instance of singleton bean 'persistentDataSource'
2010-10-22 16:29:18 DefaultListableBeanFactory [DEBUG] Creating instance of bean 'persistentDataSource'
2010-10-22 16:29:18 DefaultListableBeanFactory [DEBUG] Eagerly caching bean 'persistentDataSource' to allow for resolving potential circular references
2010-10-22 16:29:18 DefaultListableBeanFactory [DEBUG] Finished creating instance of bean 'persistentDataSource'
2010-10-22 16:29:18 DefaultListableBeanFactory [DEBUG] Creating shared instance of singleton bean 'DbLogging'
2010-10-22 16:29:18 DefaultListableBeanFactory [DEBUG] Creating instance of bean 'DbLogging'
2010-10-22 16:29:18 DefaultListableBeanFactory [DEBUG] Eagerly caching bean 'DbLogging' to allow for resolving potential circular references
2010-10-22 16:29:18 BeanUtils [DEBUG] No property editor [javax.sql.DataSourceEditor] found for type javax.sql.DataSource according to 'Editor' suffix convention
2010-10-22 16:29:18 DefaultListableBeanFactory [INFO] Destroying singletons in org.springframework.beans.factory.support.DefaultListableBeanFactory@1b45e2d5: defining beans [config,org.springframework.beans.factory.config.PropertyPlaceholderConfigurer#0,persistentDataSource,DbLogging,main]; root of factory hierarchy
2010-10-22 16:29:18 DisposableBeanAdapter [DEBUG] Invoking destroy method 'close' on bean with name 'persistentDataSource'
FAILED CONFIGURATION: @BeforeTest init
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'DbLogging' defined in class path resource [beans-config.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 'javax.sql.DataSource' for property 'datasource'; nested exception is java.lang.IllegalStateException: Cannot convert value of type [java.lang.String] to required type [javax.sql.DataSource] for property 'datasource': no matching editors or conversion strategy found
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:527)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:456)
    at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:291)
    at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:222)
    at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:288)
    at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:190)
    at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:580)
    at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:895)
    at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:425)
    at org.springframework.context.support.ClassPathXmlApplicationContext.<init>(ClassPathXmlApplicationContext.java:139)
    at org.springframework.context.support.ClassPathXmlApplicationContext.<init>(ClassPathXmlApplicationContext.java:93)
    at be.meteo.products.sender.logging.ProductStatusAppenderTest.init(ProductStatusAppenderTest.java:38)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
    at java.lang.reflect.Method.invoke(Method.java:597)
    at org.testng.internal.MethodInvocationHelper.invokeMethod(MethodInvocationHelper.java:73)
    at org.testng.internal.Invoker.invokeConfigurationMethod(Invoker.java:516)
    at org.testng.internal.Invoker.invokeConfigurations(Invoker.java:196)
    at org.testng.internal.Invoker.invokeConfigurations(Invoker.java:126)
    at org.testng.TestRunner.beforeRun(TestRunner.java:620)
    at org.testng.TestRunner.run(TestRunner.java:588)
    at org.testng.SuiteRunner.runTest(SuiteRunner.java:315)
    at org.testng.SuiteRunner.runSequentially(SuiteRunner.java:310)
    at org.testng.SuiteRunner.privateRun(SuiteRunner.java:272)
    at org.testng.SuiteRunner.run(SuiteRunner.java:221)
    at org.testng.SuiteRunnerWorker.runSuite(SuiteRunnerWorker.java:52)
    at org.testng.SuiteRunnerWorker.run(SuiteRunnerWorker.java:86)
    at org.testng.TestNG.runSuitesSequentially(TestNG.java:946)
    at org.testng.TestNG.runSuitesLocally(TestNG.java:883)
    at org.testng.TestNG.run(TestNG.java:814)
    at org.testng.remote.RemoteTestNG.run(RemoteTestNG.java:89)
    at org.testng.remote.RemoteTestNG.main(RemoteTestNG.java:144)
Caused by: org.springframework.beans.ConversionNotSupportedException: Failed to convert property value of type 'java.lang.String' to required type 'javax.sql.DataSource' for property 'datasource'; nested exception is java.lang.IllegalStateException: Cannot convert value of type [java.lang.String] to required type [javax.sql.DataSource] for property 'datasource': no matching editors or conversion strategy found
    at org.springframework.beans.BeanWrapperImpl.convertIfNecessary(BeanWrapperImpl.java:462)
    at org.springframework.beans.BeanWrapperImpl.convertForProperty(BeanWrapperImpl.java:499)
    at org.springframework.beans.BeanWrapperImpl.convertForProperty(BeanWrapperImpl.java:493)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.convertForProperty(AbstractAutowireCapableBeanFactory.java:1371)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.applyPropertyValues(AbstractAutowireCapableBeanFactory.java:1330)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean(AbstractAutowireCapableBeanFactory.java:1086)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:517)
    ... 32 more
Si je commente le bean foireux (DbLogging), j'arrive à récupérer dans le contexte la datasource et elle implémente bien javax.sql.DataSource

Voici la section relevant de mon bean de logging

Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
 
    public DataSource getDatasource() {
        return datasource;
    }
 
 
    public void setDatasource(DataSource datasource) {
        this.datasource = datasource;
    }
J'ignore ou spring va trouver que c'est une "String". Et comme il ne l'affiche pas, je n'ai pas la moindre idée de ce qu'il a été dégotter :/