IdentifiantMot de passe
Loading...
Mot de passe oublié ?Je m'inscris ! (gratuit)
Navigation

Inscrivez-vous gratuitement
pour pouvoir participer, suivre les réponses en temps réel, voter pour les messages, poser vos propres questions et recevoir la newsletter

Spring Java Discussion :

Cannot convert value of type [java.lang.String] to required type [javax.sql.DataSource] [Framework]


Sujet :

Spring Java

  1. #1
    Expert éminent sénior
    Avatar de tchize_
    Homme Profil pro
    Ingénieur développement logiciels
    Inscrit en
    Avril 2007
    Messages
    25 481
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 44
    Localisation : Belgique

    Informations professionnelles :
    Activité : Ingénieur développement logiciels
    Secteur : High Tech - Éditeur de logiciels

    Informations forums :
    Inscription : Avril 2007
    Messages : 25 481
    Points : 48 806
    Points
    48 806
    Par défaut Cannot convert value of type [java.lang.String] to required type [javax.sql.DataSource]
    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 :/

  2. #2
    Expert confirmé
    Profil pro
    Inscrit en
    Août 2006
    Messages
    3 274
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Août 2006
    Messages : 3 274
    Points : 4 141
    Points
    4 141
    Par défaut
    Essaie plutôt avec une ref :
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
     
    <bean id="DbLogging" name="LogStatusAppender"
            class="xxx.ProductStatusAppender">
            <property name="datasource" ref="persistentDataSource"/>
            </bean>
    Avec ton idref, c'est le nom persistentDataSource qui est passé en String et pas le bean lui même.

  3. #3
    Expert éminent sénior
    Avatar de tchize_
    Homme Profil pro
    Ingénieur développement logiciels
    Inscrit en
    Avril 2007
    Messages
    25 481
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 44
    Localisation : Belgique

    Informations professionnelles :
    Activité : Ingénieur développement logiciels
    Secteur : High Tech - Éditeur de logiciels

    Informations forums :
    Inscription : Avril 2007
    Messages : 25 481
    Points : 48 806
    Points
    48 806
    Par défaut
    effectivement

    mais d'après la doc, idref permet aussi de pointer un bean, tout ça est encore obscur pour moi.

  4. #4
    Membre régulier
    Profil pro
    Inscrit en
    Mars 2007
    Messages
    185
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Mars 2007
    Messages : 185
    Points : 109
    Points
    109
    Par défaut
    Bonjour,
    En fait le idref permet de passer l'id d'un bean à un autre ainsi ce code
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    <property name="datasource">
              <idref local="persistentDataSource"/>
            </property>
    est equivalent à:
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    <property name="datasource" value="persistentDataSource"/>
    la première écriture est meilleur car spring verifiera au déploiment que le bean dont l'id est idref existe.

  5. #5
    Membre expérimenté
    Avatar de Patriarch24
    Homme Profil pro
    Ingénieur développement logiciels
    Inscrit en
    Septembre 2003
    Messages
    1 047
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 40
    Localisation : France

    Informations professionnelles :
    Activité : Ingénieur développement logiciels
    Secteur : Industrie

    Informations forums :
    Inscription : Septembre 2003
    Messages : 1 047
    Points : 1 640
    Points
    1 640
    Par défaut
    Tu voulais sans doute écrire :
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    <property name="datasource" ref="persistentDataSource"/>
    Et Spring vérifie aussi la présence de ce bean. Outre le fait que c'est plus court, c'est la méthode utilisée partout dans la doc de Spring.

    Personnellement, je préfère écrire le xml sous cette forme :
    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
    <?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"
            p:driverClassName="${statusDb.driver}" p:url="${statusDb.url}" p:username="${statusDb.user}" p:password="${statusDb.password}" />
        </bean>
        <bean id="DbLogging" name="LogStatusAppender"
            class="xxx.ProductStatusAppender" p:datasource-ref="persistentDataSource"/>
    </beans>
    En premier lieu, utilisez un moteur de recherche.
    En second lieu, postez sur le forum adéquat !

  6. #6
    Expert éminent sénior
    Avatar de tchize_
    Homme Profil pro
    Ingénieur développement logiciels
    Inscrit en
    Avril 2007
    Messages
    25 481
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 44
    Localisation : Belgique

    Informations professionnelles :
    Activité : Ingénieur développement logiciels
    Secteur : High Tech - Éditeur de logiciels

    Informations forums :
    Inscription : Avril 2007
    Messages : 25 481
    Points : 48 806
    Points
    48 806
    Par défaut
    donc si j'ai bien compris, idref permet de passer le nom d'un bean (une string donc) en vérifiant que ce bean existe bien. En pratique, quel usage mon application aurait à connaitre le nom d'un bean?

  7. #7
    Membre expérimenté
    Avatar de Patriarch24
    Homme Profil pro
    Ingénieur développement logiciels
    Inscrit en
    Septembre 2003
    Messages
    1 047
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 40
    Localisation : France

    Informations professionnelles :
    Activité : Ingénieur développement logiciels
    Secteur : Industrie

    Informations forums :
    Inscription : Septembre 2003
    Messages : 1 047
    Points : 1 640
    Points
    1 640
    Par défaut
    La référence ici.
    En premier lieu, utilisez un moteur de recherche.
    En second lieu, postez sur le forum adéquat !

  8. #8
    Expert éminent sénior
    Avatar de tchize_
    Homme Profil pro
    Ingénieur développement logiciels
    Inscrit en
    Avril 2007
    Messages
    25 481
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 44
    Localisation : Belgique

    Informations professionnelles :
    Activité : Ingénieur développement logiciels
    Secteur : High Tech - Éditeur de logiciels

    Informations forums :
    Inscription : Avril 2007
    Messages : 25 481
    Points : 48 806
    Points
    48 806
    Par défaut
    merci, j'ai du mal lire en avalant la doc

+ Répondre à la discussion
Cette discussion est résolue.

Discussions similaires

  1. Réponses: 1
    Dernier message: 10/05/2015, 02h29
  2. Réponses: 2
    Dernier message: 19/07/2013, 09h20
  3. Property 'valeur' not writable on type java.lang.String
    Par bestcasaoui dans le forum Frameworks Web
    Réponses: 1
    Dernier message: 25/06/2013, 08h59
  4. Réponses: 5
    Dernier message: 01/05/2012, 13h25
  5. Réponses: 1
    Dernier message: 24/10/2011, 11h25

Partager

Partager
  • Envoyer la discussion sur Viadeo
  • Envoyer la discussion sur Twitter
  • Envoyer la discussion sur Google
  • Envoyer la discussion sur Facebook
  • Envoyer la discussion sur Digg
  • Envoyer la discussion sur Delicious
  • Envoyer la discussion sur MySpace
  • Envoyer la discussion sur Yahoo