tomcat中context.xml配置如下: <Resource name="jdbc/first"  auth="Container" 
type="javax.sql.DataSource" 
username="sa"  
password="tsx09431" 
driverClassName="com.microsoft.sqlserver.jdbc.SQLServerDriver"  
url="jdbc:sqlserver://localhost:1433;databasename=BookInfo"  
maxActive="100"  
maxIdle="30"  
maxWait="10000"/>spring中dataSource配置如下:<bean id="dataSource" class="org.springframework.jndi.JndiObjectFactoryBean">
<property name="jdbc/first">
<value>java:comp/env/jdbc/first</value>
</property>报错如下:ctory.BeanCreationException: Error creating bean with name 'hibernateTemplate' defined in file [E:\WorkBeach\Java-WorkBeach8.5\.metadata\.me_tcat\webapps\BookManagement\WEB-INF\classes\applicationContext-actions.xml]: Cannot resolve reference to bean 'sessionFactory' while setting bean property 'sessionFactory'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'sessionFactory' defined in file [E:\WorkBeach\Java-WorkBeach8.5\.metadata\.me_tcat\webapps\BookManagement\WEB-INF\classes\applicationContext-actions.xml]: Cannot resolve reference to bean 'dataSource' while setting bean property 'dataSource'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'dataSource' defined in file [E:\WorkBeach\Java-WorkBeach8.5\.metadata\.me_tcat\webapps\BookManagement\WEB-INF\classes\applicationContext-actions.xml]: Error setting property values; nested exception is org.springframework.beans.NotWritablePropertyException: Invalid property 'jdbc/first' of bean class [org.springframework.jndi.JndiObjectFactoryBean]: Bean property 'jdbc/first' is not writable or has an invalid setter method. Does the parameter type of the setter match the return type of the getter?求高手赐教,先谢了啊!

解决方案 »

  1.   

    都没人顶,还好自己搞定了,全体的错误在:
    spring中dataSource配置如下:<bean id="dataSource" class="">
    <property name="jdbc/first">
    <value>java:comp/env/jdbc/first</value>
    </property>
    将name修改成jndiName即可,呵呵,jndiName为org.springframework.jndi.JndiObjectFactoryBean
    这个类的一个属性,故这个名字是固定的,注意啦,不要犯跟我一样二的错误哈!!!
      

  2.   

    Invalid property 'jdbc/first' of bean class [org.springframework.jndi.JndiObjectFactoryBean]: Bean property 'jdbc/first' is not writable or has an invalid setter method.   无效的参数 'jdbc/first' 。 在[org.springframework.jndi.JndiObjectFactoryBean]:中类的参数 :'jdbc/first' ’是不可写的或有一个无效的方法。