ssh三大框架整合--jar包

一 ssh框架知识点回顾

1-1. Hibernate(持久层)

持久层封装与数据库相关的操作

示例:

public class BookDao
{
    public void save(Book book){
        //创建配置对象
        Configuration config = new Configuration().configure();
        //创建服务注册对象
        ServiceRegistry serviceRegistry = 
                new ServiceRegistryBuilder().applySettings(config.getProperties()).buildServiceRegistry();
        //创建sessionFactory
        SessionFactory sessionFactory = config.buildSessionFactory(serviceRegistry);
        //创建session对象,使用getCurrentSession无需显示的关闭对象
        Session session = sessionFactory.openSession();
        //创建事务对象
        Transaction tx = session.beginTransaction();
        session.save(book);
        tx.commit();
        session.close();
    }
}

1-2. Spring(业务层)

业务层实现具体的业务逻辑,接收用户请求调用相应的持久层代码实现业务需求。

示例:

public class BookService
{
    //持久层定义的类,封装对数据库的相关操作
    private BookDao bookDao;
    //Spring通过setter方法进行IOC注入
    public void setBookDao(BookDao bookDao){
        this.bookDao = bookDao;
    }

    public void save(){
        bookDao.save(book);
    }
}

xml配置文件

...
"bookDao" class="packagename.BookDao">
"bookService" class="packagename.BookService">
    "bookDao" ref="bookDao" />

...

1-3. web层(Struts2)

示例:

public class BookAction extends ActionSupport implements ModelDriven<Book>
//实现ModelDriven接口,是使用驱动模型的方式传递数据
{
    private Book book = new book();
    public Book getModel(){
        //使用模型驱动的方式
        return book;
    }

    //调用spring的业务层代码,若Struts2整合了spring则无需这么复杂
    public String save(){
        XebApplicationContext wap = WebApplicationContextUtils.getWebApplicationContext(...);
        BookService bs = wap.getBean("bookService");
        bs.save();
    }

}

二 ssh框架的相应jar包

https://yunpan.cn/ckj3tzYqfjB2W 访问密码 5871

2-1. Struts2的基本jar包

  • 下载Struts2的资源包,在其apps目录下有一个Struts2-blank.war的工程压缩包,使用解压工具打开,在其WEB-INF>lib文件夹下的jar包就是Struts2开发所需的基本jar包。
  • 了解在Struts2的lib目录下的其他jar包
    • struts2-convention-plugin.jar是struts2的注解开发jar包。
    • struts2-spring-plugin.jar是struts2用于整合spring的jar包。

2-2. hibernate需要的jar包

  • hibernate根目录下的hibernate.jar
  • hibernate/lib/required文件夹下的所有jar包
  • hibernate/lib/jpa文件夹下的所有jar包。注:JPA全称Java Persistence API.JPA通过JDK 5.0注解或XML描述对象-关系表的映射关系,并将运行期的实体对象持久化到数据库中。
  • 日志记录:slf4j的jar包整合log4j的jar包。hibernate的request文件夹下只有slf4j的jar包。log4j的jar包可在引入spring所需jar包时引入
  • 数据库驱动包JDBC

2-3. spring所需jar包

  • spring的基本开发需要引入其libs文件夹下的一下jar包
    • spring-beans.jar
    • spring-context.jar
    • spring-core.jar
    • spring-expression.jar
  • 引入spring日志记录相应的包,在spring-framework-dependencies依赖库文件夹下。
    • org.apache.log4j/com.springsource.org.apache.log4j/x.x.xx文件夹下的jar包
    • 进行日志整合的jar包(不进行具体的日志记录):在dependencies依赖库文件夹下的org.apache.commons/com.springsource.org.apache.commons.logging文件夹下的jar包。
  • springAOP需要引入的jar包
    • 在spring的libs文件夹下的spring-aop.jar
    • 在spring的libs文件夹下的spring-aspects.jar(整合aspectJ的包)
    • 引入aop联盟额一些操作:dependencies依赖库文件夹下的org.aopalliance/xxxx/xxx文件夹下的jar包
    • aspectJ的包:dependencies依赖库文件夹下的org.aspectj/com.springsource.org.asprctj.weaver/x.x.x文件夹下的jar包
  • spring的libs目录下的一些整合包:
    • 事务管理的包:spring-tx.jar
    • jdbc模板的包:spring-jdbc.jar
    • 整合hibernate的包:spring-orm.jar
    • 整合web项目:spring-web.jar
    • 整合Junit单元测试:spring-text.jar
    • 整合Struts的包:spring-struts.jar(以在引入Struts2所需包时引入了Struts2整合spring的包,所以无需再引入此包)
  • 如果想使用连接池的话导入连接池的jar包。在spring的dependencies依赖库文件夹下com.mchange.c3p0/xxx/xxx文件夹下的jar包
  • 下载slf4j的开发包,在其解压缩文件夹中找到slf4j-log4j.jar(slf4j整合log4j)

2-4. 各种jar包的maven依赖坐标

<dependencys>

<dependency><groupId>org.luceegroupId><artifactId>antlrartifactId><version>2.7.6version>dependency>

<dependency><groupId>asmgroupId><artifactId>asmartifactId><version>3.3version>dependency>

<dependency><groupId>asmgroupId><artifactId>asm-commonsartifactId><version>3.3version>dependency>

<dependency><groupId>asmgroupId><artifactId>asm-treeartifactId><version>3.3version>dependency>

<dependency><groupId>not findgroupId><artifactId>com.springsource.com.mchange.v2.c3p0artifactId><version>0.9.1.2version>dependency>

<dependency><groupId>not findgroupId><artifactId>com.springsource.org.aopallianceartifactId><version>1.0.0version>dependency>

<dependency><groupId>not findgroupId><artifactId>com.springsource.org.apache.commons.loggingartifactId><version>1.1.1version>dependency>

<dependency><groupId>not findgroupId><artifactId>com.springsource.org.apache.log4jartifactId><version>1.2.15version>dependency>

<dependency><groupId>not findgroupId><artifactId>com.springsource.org.aspectj.weaverartifactId><version>1.6.8.RELEASEversion>dependency>

<dependency><groupId>commons-collectionsgroupId><artifactId>commons-collectionsartifactId><version>3.1version>dependency>

<dependency><groupId>commons-fileuploadgroupId><artifactId>commons-fileuploadartifactId><version>1.2.2version>dependency>

<dependency><groupId>commons-iogroupId><artifactId>commons-ioartifactId><version>2.0.1version>dependency>

<dependency><groupId>org.apache.commonsgroupId><artifactId>commons-lang3artifactId><version>3.1version>dependency>

<dependency><groupId>org.luceegroupId><artifactId>commons-loggingartifactId><version>1.1.1version>dependency>

<dependency><groupId>org.luceegroupId><artifactId>dom4jartifactId><version>1.6.1version>dependency>

<dependency><groupId>org.freemarkergroupId><artifactId>freemarkerartifactId><version>2.3.19version>dependency>

<dependency><groupId>not findgroupId><artifactId>hibernate-jpa-apiartifactId><version>2.0-1.0.0.Finalversion>

dependency><dependency><groupId>not findgroupId><artifactId>hibernate3artifactId><version>version>dependency>

<dependency><groupId>javassistgroupId><artifactId>javassistartifactId><version>3.11.0.GAversion>dependency>

<dependency><groupId>javassistgroupId><artifactId>javassistartifactId><version>3.12.0.GAversion>dependency>

<dependency><groupId>org.atteo.moonshinegroupId><artifactId>jtaartifactId><version>1.1version>dependency>

<dependency><groupId>ognlgroupId><artifactId>ognlartifactId><version>3.0.6version>dependency>

<dependency><groupId>org.slf4jgroupId><artifactId>slf4j-apiartifactId><version>1.6.1version>dependency>

<dependency><groupId>org.springframeworkgroupId><artifactId>spring-aopartifactId><version>4.0.0.RELEASEversion>dependency>

<dependency><groupId>org.springframeworkgroupId><artifactId>spring-aspectsartifactId><version>4.0.0.RELEASEversion>dependency>

<dependency><groupId>org.springframeworkgroupId><artifactId>spring-beansartifactId><version>4.0.0.RELEASEversion>dependency>

<dependency><groupId>org.springframeworkgroupId><artifactId>spring-contextartifactId><version>4.0.0.RELEASEversion>dependency>

<dependency><groupId>org.springframeworkgroupId><artifactId>spring-coreartifactId><version>4.0.0.RELEASEversion>dependency>

<dependency><groupId>org.springframeworkgroupId><artifactId>spring-expressionartifactId><version>4.0.0.RELEASEversion>dependency>

<dependency><groupId>org.springframeworkgroupId><artifactId>spring-jdbcartifactId><version>4.0.0.RELEASEversion>dependency>

<dependency><groupId>org.springframeworkgroupId><artifactId>spring-ormartifactId><version>4.0.0.RELEASEversion>dependency>

<dependency><groupId>org.springframeworkgroupId><artifactId>spring-testartifactId><version>4.0.0.RELEASEversion>dependency>

<dependency><groupId>org.springframeworkgroupId><artifactId>spring-txartifactId><version>4.0.0.RELEASEversion>dependency>

<dependency><groupId>org.springframeworkgroupId><artifactId>spring-webartifactId><version>4.0.0.RELEASEversion>dependency>

<dependency><groupId>org.apache.strutsgroupId><artifactId>struts2-coreartifactId><version>2.3.12version>dependency>

<dependency><groupId>org.apache.strutsgroupId><artifactId>struts2-spring-pluginartifactId><version>2.3.12version>dependency>

<dependency><groupId>org.apache.struts.xworkgroupId><artifactId>xwork-coreartifactId><version>2.3.12version>dependency>

dependencys>

相关链接:

ssh三大框架整合–jar包
ssh三大框架整合–配置文件
ssh三大框架整合–整合实例

你可能感兴趣的:(Spring,Hiberbate,Struts2)