Maven项目集成Spring+SpringMVC+SpringDataJpa的项目配置

Maven项目集成Spring+SpringMVC+SpringDataJpa的项目配置

Spring的配置文件


<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:tx="http://www.springframework.org/schema/tx"
       xmlns:jpa="http://www.springframework.org/schema/data/jpa"
       xsi:schemaLocation="
       http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
       http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd
       http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx.xsd
       http://www.springframework.org/schema/data/jpa http://www.springframework.org/schema/data/jpa/spring-jpa.xsd
">

    
    <context:component-scan base-package="wltyx.nyybw.aisell.service"/>
    
    <context:property-placeholder location="classpath:db/jdbc.properties"/>
    
    <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="wltyx.nyybw.aisell.domain"/>
        
        <property name="jpaVendorAdapter">
            <bean class="org.springframework.orm.jpa.vendor.HibernateJpaVendorAdapter">
                
                <property name="databasePlatform" value="org.hibernate.dialect.MySQLDialect"/>
                
                <property name="generateDdl" value="false"/>
                
                <property name="showSql" value="true"/>
            bean>
        property>
    bean>
    
    <bean id="transactionManager" class="org.springframework.orm.jpa.JpaTransactionManager">
        <property name="entityManagerFactory" ref="entityManagerFactory"/>
    bean>
    
    <tx:annotation-driven/>
    
    <jpa:repositories
            base-package="wltyx.nyybw.aisell.repository"
            transaction-manager-ref="transactionManager"
            entity-manager-factory-ref="entityManagerFactory"
            factory-class="wltyx.nyybw.aisell.repository.BaseRepositoryFactoryBean"
    />
beans>

SpringMVC的配置文件


<beans xmlns="http://www.springframework.org/schema/beans"
       xmlns:context="http://www.springframework.org/schema/context"
       xmlns:mvc="http://www.springframework.org/schema/mvc"
       xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
       xsi:schemaLocation="
       http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
       http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd
       http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc.xsd
">
    
    <context:component-scan base-package="wltyx.nyybw.aisell.web.controller"/>
    
    <mvc:default-servlet-handler/>
    
    <mvc:annotation-driven/>
    
    <bean class="org.springframework.web.servlet.view.InternalResourceViewResolver">
        <property name="prefix" value="/WEB-INF/views/"/>
        <property name="suffix" value=".jsp"/>
    bean>
beans>

web.xml配置


<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://xmlns.jcp.org/xml/ns/javaee"
        xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/web-app_3_1.xsd"
        id="WebApp_ID" version="3.1">

 
 
 <context-param>
   <param-name>contextConfigLocationparam-name>
   <param-value>classpath:applicationContext.xmlparam-value>
 context-param>
 
 <listener>
   <listener-class>org.springframework.web.context.ContextLoaderListenerlistener-class>
 listener>

 
 <servlet>
   <servlet-name>springMVCservlet-name>
   <servlet-class>org.springframework.web.servlet.DispatcherServletservlet-class>
   
   <init-param>
     <param-name>contextConfigLocationparam-name>
     <param-value>classpath:applicationContext-mvc.xmlparam-value>
   init-param>
   
   <load-on-startup>1load-on-startup>
 servlet>
 <servlet-mapping>
   <servlet-name>springMVCservlet-name>
   <url-pattern>/url-pattern>
 servlet-mapping>

 
 <filter>
   <filter-name>CharacterEncodingFilterfilter-name>
   <filter-class>org.springframework.web.filter.CharacterEncodingFilterfilter-class>
   
   <init-param>
     <param-name>encodingparam-name>
     <param-value>UTF-8param-value>
   init-param>
   <init-param>
     <param-name>forceEncodingparam-name>
     <param-value>trueparam-value>
   init-param>
 filter>
 <filter-mapping>
   <filter-name>CharacterEncodingFilterfilter-name>
   <url-pattern>/*url-pattern>
 filter-mapping>
web-app>

你可能感兴趣的:(SSSDJ框架集成)