SSJ整合配置

SSJ课程笔记

1.1 三大框架认识

ssh:struts2+spring+hibernate – 一般是老的项目在使用

sssj:springmvc+spring+springjdbc – 第一个项目在使用

ssj:springmvc+spring+jpa (今天任务)

sssdj:springmvc+spring+springdatajpa–第二个项目使用方式

ssm:springmvc+ spring+ mybatis (项目比较流行) – 第三个项目和 第四个项目

1.2 spring+jpa整合

(1)整合步骤:

​ 先配置jdbc.properties --》dataSource -->EntityManagerFactory–>EntityManager–>TransactionManager

(2)创建一个web的maven项目, 导入pom的依赖包

 <dependencies>
     
    <dependency>
      <groupId>org.springframeworkgroupId>
      <artifactId>spring-webartifactId>
      <version>4.2.5.RELEASEversion>
    dependency>
    <dependency>
      <groupId>org.springframeworkgroupId>
      <artifactId>spring-webmvcartifactId>
      <version>4.2.5.RELEASEversion>
    dependency>
     
    <dependency>
      <groupId>org.springframeworkgroupId>
      <artifactId>spring-jdbcartifactId>
      <version>4.2.5.RELEASEversion>
    dependency>
     
    <dependency>
      <groupId>org.springframeworkgroupId>
      <artifactId>spring-ormartifactId>
      <version>4.2.5.RELEASEversion>
    dependency>
     
    <dependency>
      <groupId>org.hibernategroupId>
      <artifactId>hibernate-coreartifactId>
      <version>4.3.8.Finalversion>
    dependency>
    <dependency>
      <groupId>org.hibernategroupId>
      <artifactId>hibernate-entitymanagerartifactId>
      <version>4.3.8.Finalversion>
    dependency>
    <dependency>
      <groupId>mysqlgroupId>
      <artifactId>mysql-connector-javaartifactId>
      <version>5.1.6version>
    dependency>
     
    <dependency>
      <groupId>commons-dbcpgroupId>
      <artifactId>commons-dbcpartifactId>
      <version>1.2.2version>
    dependency>
 	 
    <dependency>
      <groupId>org.springframeworkgroupId>
      <artifactId>spring-testartifactId>
      <version>4.2.5.RELEASEversion>
    dependency>
	
    <dependency>
      <groupId>org.aspectjgroupId>
      <artifactId>aspectjweaverartifactId>
      <version>1.8.9version>
    dependency>
     
    <dependency>
      <groupId>com.fasterxml.jackson.coregroupId>
      <artifactId>jackson-databindartifactId>
      <version>2.6.5version>
    dependency>

    <dependency>
      <groupId>junitgroupId>
      <artifactId>junitartifactId>
      <version>4.11version>
      <scope>testscope>
    dependency>
  dependencies>

(3)配置xml


    <context:property-placeholder location="classpath:jdbc.properties"/>

    
    <context:component-scan base-package="cn.itsource.ssj"/>

    
    <bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource" destroy-method="close">
        
        
        
        <property name="driverClassName" value="${jdbc.driverClassName}" />
        <property name="url" value="${jdbc.url}" />
        <property name="username" value="${jdbc.username}" />
        <property name="password" value="${jdbc.password}" />
    bean>
    
    <bean id="entityManagerFactory" class="org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean">
        
        <property name="dataSource"  ref="dataSource"/>
       
        <property name="packagesToScan" value="cn.itsource.ssj.domain"/>

        <property name="jpaVendorAdapter" >
            <bean class="org.springframework.orm.jpa.vendor.HibernateJpaVendorAdapter">
                
                <property name="showSql" value="true" />
                
                <property name="generateDdl" value="true" />
                
                <property name="databasePlatform" value="org.hibernate.dialect.MySQLDialect" />
            bean>
        property>
    bean>

    
    <bean id="transactionManager" class="org.springframework.orm.jpa.JpaTransactionManager">
        <property name="entityManagerFactory" ref="entityManagerFactory"/>
    bean>
    
    <tx:annotation-driven/>

(4)创建dao层 service层

1.3 springmvc+spring整合

(1)在pom.xml里面添加依赖 spring-webmvc.jar

(2)配置文件

你可能感兴趣的:(学习)