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.9k
撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进
推荐问题