Evil_Hao
流水无情丶
2017-03-28 14:02
采纳率: 66.7%
浏览 1.5k
已采纳

Spring4 JDBC 通过JNDI获取数据源

为什么 jndi的id属性一定要是dataSource,如果不是dataSource就报错

 <jee:jndi-lookup id="dataSource" jndi-name="jdbc/ORCL" resource-ref="true"/>

  <bean id="jdbcTemplate" class="org.springframework.jdbc.core.JdbcTemplate">
    <property name="dataSource" ref="dataSource" />
  </bean>
如果将JNDI的id属性设置为datasource,将会报错:
org.springframework.beans.factory.BeanCreationException: 
Error creating bean with name 'helloWorld': Injection of autowired dependencies failed;
nested exception is org.springframework.beans.factory.BeanCreationException: Could not autowire field: private com.it.dao.Seacher com.it.controller.HelloWorld.seacher; 
nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'seacher' defined in class path resource [springmvc.xml]: Cannot resolve reference to bean 'jdbcTemplate' while setting bean property 'jdbcTemplate'; 
nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'jdbcTemplate' defined in class path resource [springmvc.xml]: Error setting property values;
nested exception is org.springframework.beans.NotWritablePropertyException: Invalid property 'datasource' of bean class [org.springframework.jdbc.core.JdbcTemplate]: Bean property 'datasource' is not writable or has an invalid setter method. Did you mean 'dataSource'?
  • 点赞
  • 写回答
  • 关注问题
  • 收藏
  • 邀请回答

2条回答 默认 最新

  • youcaihuahy
    Leon0720 2017-03-29 00:52
    已采纳

    这里的name一定是dataSource,ref只要和自己定义的id一样即可

    点赞 评论
  • guojinshuiCSDN
    郭金水 2017-03-28 14:17

    图片说明

    好多东西都是规定好的 。 怎么能改呢

    点赞 评论

相关推荐