Spring4
Bean的配置
Helloworld文件中:
ApplicationContext.xml文件中:
分别是属性注入和构造器注入。构造器注入可选用index和type。
记得给类写get/set方法,同时注意无参和有参构造器。
赋null值:<null/>
此处注意:Properties是Hashtable的实现类。
scope = "singleton"时, 会自动创建该实例,不需要调用就会自动创建。
而scope="prototype"时,只有Main方法创建一个 ApplicationContext时才创建。
注意引入 context 命名空间。
构造顺序:
有 init-method、destroy-method 参数。
1.构造器 2.set 方法 3.前置初始化 4.ini t方法 5.后置初始化 6.Main 方法 7.destroy 方法
constructor-arg 的参数是图上的 getCar 初始化方法的参数。
注意 Respository 属性有一个表示在 ioc 容器中 id 的 value 参数。
1:Autowired(required=false);
2:当有多个实现同一个接口的类,可以用@Repository("")来确定。(Autowired特有)
Spring AOP
Spring 对 JDBC 的支持
Spring 中的事务管理
上面的内容并没有用上 spring 对事务的处理,下面提到了。
同时在对应的方法加上事务注解即可。
下面是采用注解的方式配置:
下面是采用xml文件的方式配置:
Spring 整合 Hibernate
Spring 整合 struct
整合 struct1:
整合 struct2: