基于Eclipse的Spring4.3.3配置获取DataSource详解
来源:互联网 发布:导播软件 编辑:程序博客网 时间:2024/06/08 08:58
笔者之前用的是MyEclipse 2016 CI 1,MyEclipse内配的Spring版本是4.1.1,以下是Spring4.1.1版本的DataSource配置代码:
<bean id="dataSource"class="org.springframework.jdbc.datasource.DriverManagerDataSource"><property name="driverClassName" value="oracle.jdbc.driver.OracleDriver"></property><property name="url" value="jdbc:oracle:thin:@localhost:1521:orcl"></property><property name="username" value="scott"></property><property name="password" value="tiger"></property></bean>
现在用的是Eclipse 4.6Neon,Spring4.3.3,把以上4.1.1版本的配置代码拷贝到现在的程序中执行,出现以下异常:
Error creating bean with name 'dataSource' defined in class path resource [beans.xml]: Error setting property values; nested exception is org.springframework.beans.NotWritablePropertyException: Invalid property 'driverClass' of bean class [org.springframework.jdbc.datasource.DriverManagerDataSource]: Bean property 'driverClass' is not writable or has an invalid setter method. Does the parameter type of the setter match the return type of the getter?
配置文件运行到<property name="aaa" value="bbb" />时会通过反射获取setAaa方法,bbb作为形参值注入,
而根据异常得知DriverManagerDataSource中没有aaa属性,找到DriverManagerDataSource.class打开查看
若没有添加源码打开后点击Attach Source找到Spring所在目录添加对应的spring-xxx-x.x.x.RELEASE-sources.jar即可
可以看到DriverManagerDataSource没有定义任何属性,CTRL+左击 点击父类AbstractDriverBaseDataSource查看
可以看见包含属性url、username、password、catalog、schema、connectionProperties且都已有对应的setter和getter方法,即这几个属性可通过Spring配置bean property注入,而这版本中driverClassName已被移除,固无需设置,以下乃配置图及测试图(连接池的连接数配置是一些书上的案例,但在DriverManagerDataSource及其父类中都没有这些属性,所以设置这些属性将会出现与设置driverManagerClassName相同的异常——属性不存在):
- 基于Eclipse的Spring4.3.3配置获取DataSource详解
- Spring的datasource配置详解
- spring4配置基于注解的ehcache缓存
- SpringBoot DataSource配置详解
- 基于Eclipse Maven的Spring4/Spring-MVC/Hibernate4整合之一 : Maven的pom.xml环境配置及注意方面
- 基于Eclipse Maven的Spring4/Spring-MVC/Hibernate4整合之二: Spring/proxool数据源/Hibernate的配置
- 获取Datasource的DataBase
- Spring的dataSource配置
- 数据库连接datasource的配置
- Spring的DataSource配置
- 一段spring4的配置
- spring4 -- 基于jdbcTemplate的分页
- struts下的datasource配置
- WebLogic的简单DataSource配置
- spring的各种dataSource配置
- spring中datasource的配置
- websphere 中datasource 的配置
- Spring3 配置datasource 的方法
- Android中的Service 与 Thread 的区别
- JQuery 常用DOM操作5
- gem安装时出现 undefined method `size' for nil:NilClass (NoMethodError) 的解决办法
- (3).Mybatis动态sql的使用
- Struts配置文件中的action元素属性
- 基于Eclipse的Spring4.3.3配置获取DataSource详解
- Git快速上手
- mysqld_safe详解
- ActionForm Bean的作用
- R.drawable.找不到图片资源
- alibaba Otter binlog数据管理台manager权限配置修改
- ActionForm执行步骤
- PHP面试中常见的字符串与文件操作
- Android常用动画的回顾