日期:2014-05-20  浏览次数:20804 次

ssh2+tomcat+sqlserver2005 的一个项目配置jndi时报错,具体如下:
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?

求高手赐教,先谢了啊!

------解决方案--------------------
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' ’是不可写的或有一个无效的方法。