java框架(SSM)
持久层ORM框架:mybatis框架 轻量级(半自动化) 自己来编写sql 【Hibernate 重量级 没有sql 较早】
MVC框架:模型 视图 处理器
javaWeb(Dao service/jsp/serviet) springMVC(目前企业使用较多)【Struts/Struts2】
IOC容器框架 Spring 流行 (全家桶)
SSH(Spring/struts/hibernate)
SSM(Spring/SpringMVC/mybatis)
SSH2(Spring/struts2/hibernate)
Spring 框架
1.Spring是什么
1.是一个开源框架
2.为简化企业级应用开发而生,使用Spring可以使简单的javaBean实现以前只有EJB才能实现的功能
3.是一个IOC(DI)和AOP容器框架
2.Spring具体描述
1.轻量级:Spring使非侵入性的-基于Spring开发的应用中的对象可以不依赖于Spring的API
2.依赖注入(DI---Dependency injection,IOC(控制反转))
3.面向切面编程:(AOP---aspect oriented programming)
4.容器:Spring是一个容器,因为它包含并且管理应用对象的生命周期
5.框架:Spring实现了使用简单的组件配置组合成一个复杂的应用,在Spring中可以使用XML和java注解组合这些对象
6.一站式:在IOC和AOP的基础上可以整合各种企业应用的开源框架和优秀的第三方类库(实际上Spring自身也提供了展现层的SpringMVC和持久层的SpringJDBC)
3.Spring模块
1.Data Access/Integration(SpringJDBC持久层):
(JDBC,ORM(持久层框架的集成),OXM,JMS(消息服务),Transactions(事务))
2.Web(SpringMVC展现层):
(WebSocket,Servlet,Web,Portlet(独立小方块应用))
3.AOP(面向切面编程)
4.Aspects(切面)
5.Instruction
6.Messaging(消息)
7.Core Container(最底层 核心容器):
(Beans(javaBean),Core(内核),Context(容器上下文),SpEL(SpringEL表达式))
4.Spring环境准备
1.Spring下载/ZIP包下载
2.安装Spring tool suite(如果使用eclipse,STS无需安装)
5.搭建Spring开发环境
1.把jar包加入到工程的classpath下
commons-logging-1.1.1.jar
spring-beans-4.3.10.RELEASE.jar
spring-context-4.3.10.RELEASE.jar
spring-core-4.3.10.RELEASE.jar
spring-expression-4.3.10.RELEASE.jar
2.Spring的配置文件:一个典型的Spring项目需要创建一个或多个Bean配置文件,
这些配置文件用于Spring IOC容器里配置Bean。Bean的配置文件可以放在classpath下,
也可以放在其他目录下(新建Spring Bean Definition file)
6.Spring的使用
eg
1.新建java类HelloWord
public class HelloWord {
private String name;
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public void hello() {
System.out.println("hello: "+name);
}
}
原始使用的话
//原始直接new
// HelloWord hello = new HelloWord();
// hello.setName("zhangsan");
// hello.hello();
现在通过Spring管理 调取值 生成
2.在applicationContext.xml配置Bean
<?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:util="http://www.springframework.org/schema/util"
xmlns:p="http://www.springframework.org/schema/p"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
http://www.springframework.org/schema/util http://www.springframework.org/schema/util/spring-util-4.3.xsd">
<bean name="helloWord" class="org.spring.beans.HelloWord"></bean>
</beans>
3.测试类使用
public class Test1 {
public static void main(String[] args) {
//通过Spring
//1.创建Spring容器对象
ApplicationContext ctx = new ClassPathXmlApplicationContext("applicationContext.xml");
//2.从容器获取实例 ("helloWord")为xml配置的Bean名称
HelloWord hello = (HelloWord) ctx.getBean("helloWord");
//3.对象方法调用
hello.setName("zhangsan");
hello.hello();
}
}