Spring2.5的设值注入可以不用定义属性变量,有set属性名 函数就可以了
2012-01-07 22:53
447 查看
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) {。。。
今天学习了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) {。。。
相关文章推荐
- static(c中定义的关键字1、被其修饰者 外部无法使用(相反的都可以使用extern在外部使用) 2、函数局部变量使用成为静态的放入静态池-生存期改变。c++进行了扩充,使它在类中有了特殊作用)
- Spring中使用Map、Set、List、数组、属性集合的注入方法配置文件
- Spring中使用Map、Set、List、数组、属性集合的注入方法配置文件
- SSH与SSM学习之Spring04——Spring属性注入之set方法注入
- Spring中如何向Bean注入系统属性或环境变量
- Spring基于xml配置文件对list、set、map集合的属性注入
- Spring中使用Map、Set、List、数组、属性集合的注入方法配置文件
- JBuilder可以根据属性生成set和get函数
- 在 JavaScript 核心语言中,全局对象的预定义属性都是不可枚举的,所有可以用 for/in 循环列出所有隐式或显式声明的全局变量
- c语言中同一函数下不可以重复定义变量
- Spring IoC – 属性注入 – set方法和构造方法
- spring 注入变量不可以改成静态变量
- Spring 普通属性注入(int ,String, List, Map, Set, String[])
- 2.19访问模块(函数或变量)的属性,可以通过句点属性表示法。
- Spring中使用Map、Set、List、数组、属性集合的注入方法配置文件
- spring中依赖注入 属性无set方法
- Spring 配置bean, 注解方式配置 xml方式要生产set方法方便属性注入,注解方式不需要,利用反射机制注入
- Spring通过set方法注入Bean属性
- Spring中使用Map、Set、List、数组、属性集合的注入方法配置文件
- Spring中使用Map、Set、List、数组、属性集合的注入方法配置文件