这是我的spring-context.xml
<!-- 引入配置文件 --> <context:property-placeholder location="classpath:config.properties" /> <!-- 配置数据源 --> <bean id="dataSource" class="org.logicalcobwebs.proxool.ProxoolDataSource"> <property name="driver" value="${jdbc.driver}" /> <property name="driverUrl" value="${jdbc.url}" /> <property name="user" value="${jdbc.username}" /> <property name="password" value="${jdbc.password}" /> <property name="minimumConnectionCount" value="${jdbc.minConnection}" /> <property name="maximumConnectionCount" value="${jdbc.maxConnection}" /> <property name="maximumConnectionLifetime" value="${jdbc.maxConnectionLife}" /> <property name="maximumActiveTime" value="${jdbc.maxActiveTime}" /> <property name="prototypeCount" value="${jdbc.prototypeCount}" /> <property name="houseKeepingTestSql" value="${jdbc.testSql}" /> </bean> <!-- 配置事务管理器 --> <bean id="transactionManager" class="org.springframework.jdbc.datasource.DataSourceTransactionManager"> <property name="dataSource" ref="dataSource" /> </bean> <!-- 注解方式配置事物 --> <tx:annotation-driven transaction-manager="transactionManager" /> <!-- 注解解析 --> <context:annotation-config /> <!-- 扫描所有spring bean注解 --> <context:component-scan base-package="bhz" /> <!-- 动态代理 --> <aop:aspectj-autoproxy/> </beans>
发布到tomcat后运行报错:Error creating bean with name 'dataSource' defined in URL [file:/J:/Architecture/.metadata/.plugins/org.eclipse.wst.server.core/tmp0/wtpwebapps/bhz-sys/WEB-INF/classes/spring-context.xml]: Error setting property values; nested exception is org.springframework.beans.NotWritablePropertyException: Invalid property 'maximumConnectionLifetime' of bean class [org.logicalcobwebs.proxool.ProxoolDataSource]: Bean property 'maximumConnectionLifetime' is not writable or has an invalid setter method. Does the parameter type of the setter match the return type of the getter?
一下午没找到原因,期望各位大佬帮忙看下怎么解决
没有找到这个属性。我刚看了一下
<dependency> <groupId>org.sction.proxool</groupId> <artifactId>proxool</artifactId> <version>0.9.1</version> </dependency>
的源代码。看现一个奇怪的现象:
private long maximumConnectionLifetime;
//get seter 方法
public long getMaximumConnectionLifetime() {
return maximumConnectionLifetime;
}
seter 方法
public void setMaximumConnectionLifetime(int maximumConnectionLifetime) {
this.maximumConnectionLifetime = maximumConnectionLifetime;
}
setter方法定义是long,setting是int。反射是找不到set方法。所以spring的Ioc报错了。。我在网上找到一篇类似的文章
http://post.blogchina.com/p/1233554
感谢老铁,已经解决