您的位置:首页 > 编程语言 > Java开发

Spring2.5的设值注入可以不用定义属性变量,有set属性名 函数就可以了

2012-01-07 22:53 399 查看
Spring2.5的设值注入可以不用定义属性变量,有set属性名 函数就可以了。

今天学习了spring的一个教材,发现可以不用定义属性变量,有set属性名 函数就可以了。

<?xml version="1.0" encoding="UTF-8"?>

<beans xmlns="http://www.springframework.org/schema/beans"

xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:aop="http://www.springframework.org/schema/aop"

xmlns:tx="http://www.springframework.org/schema/tx"

xsi:schemaLocation="
http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.5.xsd
http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-2.5.xsd
http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-2.5.xsd">

<bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource"

destroy-method="close">

<property name="driverClassName" value="org.gjt.mm.mysql.Driver" />

<property name="url"

value="jdbc:mysql://192.168.1.100:3306/xoops?userUnicode=true&characterencoding=UTF-8" />

<property name="username">

<value>xoops_root</value>

</property>

<property name="password" value="654321" />

<!-- 连接池启动时的初始值 -->

<property name="initialSize" value="1" />

<!-- 连接池的最大值 -->

<property name="maxActive" value="256" />

<!-- 最大空闲值 -->

<property name="maxIdle" value="4" />

<!-- 最小空闲值 -->

<property name="minIdle" value="1" />

</bean>

<bean id="txManager"

class="org.springframework.jdbc.datasource.DataSourceTransactionManager">

<property name="dataSource" ref="dataSource" />

</bean>

<tx:annotation-driven transaction-manager="txManager" />

<bean id="personService" class="personInterface.Impl.PersonServiceBean">

<property name="dataSource" ref="dataSource" />

</bean>


</beans>

public class PersonServiceBean implements PersonService {

private JdbcTemplate jdbcTemplate;

public void setDataSource(DataSource dataSource) {

this.jdbcTemplate = new JdbcTemplate(dataSource);


}

@Override

public void save(Person person) {。。。
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: 
相关文章推荐