struts2
显示层:MVC
hibernate:
持久层:ORM
spring:
业务层:
导入jar包:
控制反转(IOC):Inversion of Control
管理bean
配置xml文件:
applicationContext.xml
beans.xml
<?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:context="http://www.springframework.org/schema/context"
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/context
http://www.springframework.org/schema/context/spring-context-2.5.xsd
http://www.springframework.org/schema/aop
http://www.springframework.org/schema/aop/spring-aop-2.5.xsd
http://www.springframework.org/schema/tx
http://www.springframework.org/schema/tx/spring-tx-2.5.xsd
">
</beans>
</xml>
依赖注入(DI):(Dependency Injection)
配置文件注入
两种注入方式:
Set方法注入
构造方法注入
注入各种类型
普通类型
其它Bean对象
null值
集合类型
注解注入:
在主配置文件中申明注解
<context:component-scan base-package="spring2test.bean"></context:component-scan>
@Resource(name="" )//用于成员变量
作用一样
@Component//主要用于类(作用域)中
@Service//主要用于业务层
@Controller//主要控制层
@Repository//主要持久层
@Scope("prototype")//设置为多例(原型),默认为单例
API:
Resource
BeanFactory
ApplicationContext(推荐)
ClassPathXmlApplicationContext
方法
getBean();
获取定义的bean的总数量
getBeanDefinitionCount()
getBeanDefinitionNames();
getBeansOfType();//返回String[]
getBeanForType();//返回Map<String,Object>
bean的作用域:
singleton:单例
prototype:原型
request:
session
global session
面向切面编程(AOP):Aspect Oriented Programing
切入点(作用于哪里)+通知(做什么事):横切关注点(切面)
切入点表达式:
executer(* *(..))
申明切入点---->>申明通知--->>生成切面--->增加这个切面生成相应的代理对象
API:
与其他框架整合(SSH)
解耦
SS整合:
导入jar包
在web.xml中配置监听器和struts2的过滤器
<listener>
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>classpath:applicationContext*.xml</param-value>
</context-param>
<filter>
<filter-name>struts2</filter-name>
<filter-class>org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter</filter-class>
</filter>
<filter-mapping>
<filter-name>struts2</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
添加一个Struts2的插件jar包\
与JDBC的融合
API:
JdbcTemplate
--------------------
代理:
静态代理:
需要都实现接口
JDK方式动态代理:
一定要实现接口:
需要实现:InvocationHandler
Proxy.newProxyInstance(loader, interfaces, h)
cglib方式动态代理
final的类,方法不能代理,
需要实现:MethodInterceptor
显示层:MVC
hibernate:
持久层:ORM
spring:
业务层:
导入jar包:
控制反转(IOC):Inversion of Control
管理bean
配置xml文件:
applicationContext.xml
beans.xml
<?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:context="http://www.springframework.org/schema/context"
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/context
http://www.springframework.org/schema/context/spring-context-2.5.xsd
http://www.springframework.org/schema/aop
http://www.springframework.org/schema/aop/spring-aop-2.5.xsd
http://www.springframework.org/schema/tx
http://www.springframework.org/schema/tx/spring-tx-2.5.xsd
">
</beans>
</xml>
依赖注入(DI):(Dependency Injection)
配置文件注入
两种注入方式:
Set方法注入
构造方法注入
注入各种类型
普通类型
其它Bean对象
null值
集合类型
注解注入:
在主配置文件中申明注解
<context:component-scan base-package="spring2test.bean"></context:component-scan>
@Resource(name="" )//用于成员变量
作用一样
@Component//主要用于类(作用域)中
@Service//主要用于业务层
@Controller//主要控制层
@Repository//主要持久层
@Scope("prototype")//设置为多例(原型),默认为单例
API:
Resource
BeanFactory
ApplicationContext(推荐)
ClassPathXmlApplicationContext
方法
getBean();
获取定义的bean的总数量
getBeanDefinitionCount()
getBeanDefinitionNames();
getBeansOfType();//返回String[]
getBeanForType();//返回Map<String,Object>
bean的作用域:
singleton:单例
prototype:原型
request:
session
global session
面向切面编程(AOP):Aspect Oriented Programing
切入点(作用于哪里)+通知(做什么事):横切关注点(切面)
切入点表达式:
executer(* *(..))
申明切入点---->>申明通知--->>生成切面--->增加这个切面生成相应的代理对象
API:
与其他框架整合(SSH)
解耦
SS整合:
导入jar包
在web.xml中配置监听器和struts2的过滤器
<listener>
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>classpath:applicationContext*.xml</param-value>
</context-param>
<filter>
<filter-name>struts2</filter-name>
<filter-class>org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter</filter-class>
</filter>
<filter-mapping>
<filter-name>struts2</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
添加一个Struts2的插件jar包\
与JDBC的融合
API:
JdbcTemplate
--------------------
代理:
静态代理:
需要都实现接口
JDK方式动态代理:
一定要实现接口:
需要实现:InvocationHandler
Proxy.newProxyInstance(loader, interfaces, h)
cglib方式动态代理
final的类,方法不能代理,
需要实现:MethodInterceptor