maven文件合集
阅读原文时间:2023年07月08日阅读:3

maven项目目录结构

聚合项目的pom.xml


http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
4.0.0

com.ldf
manager
pom
1.0-SNAPSHOT
manager-pojo manager-service manager-web manager-mapper


4.12 4.1.3.RELEASE 3.2.8 1.2.2 5.1.32 1.0.9 1.2 2.5 2.0 2.2



junit junit ${junit.version}

  <!--mybatis-->  
  <dependency>  
    <groupId>org.mybatis</groupId>  
    <artifactId>mybatis</artifactId>  
    <version>${mybatis.version}</version>  
  </dependency>  
  <dependency>  
    <groupId>org.mybatis</groupId>  
    <artifactId>mybatis-spring</artifactId>  
    <version>${mybatis.spring.version}</version>  
  </dependency>

  <!--mysql-->  
  <dependency>  
    <groupId>mysql</groupId>  
    <artifactId>mysql-connector-java</artifactId>  
    <version>${mysql.version}</version>  
  </dependency>  
  <dependency>  
    <groupId>com.alibaba</groupId>  
    <artifactId>druid</artifactId>  
    <version>${druid.version}</version>  
  </dependency>

  <!--spring-->  
  <dependency>  
    <groupId>org.springframework</groupId>  
    <artifactId>spring-context</artifactId>  
    <version>${spring.version}</version>  
  </dependency>  
  <dependency>  
    <groupId>org.springframework</groupId>  
    <artifactId>spring-beans</artifactId>  
    <version>${spring.version}</version>  
  </dependency>  
  <dependency>  
    <groupId>org.springframework</groupId>  
    <artifactId>spring-jdbc</artifactId>  
    <version>${spring.version}</version>  
  </dependency>  
  <dependency>  
    <groupId>org.springframework</groupId>  
    <artifactId>spring-webmvc</artifactId>  
    <version>${spring.version}</version>  
  </dependency>  
  <dependency>  
    <groupId>org.springframework</groupId>  
    <artifactId>spring-aspects</artifactId>  
    <version>${spring.version}</version>  
  </dependency>  
  <dependency>  
    <groupId>org.springframework</groupId>  
    <artifactId>spring-test</artifactId>  
    <version>${spring.version}</version>  
  </dependency>

  <!--jsp&servlet-->  
  <dependency>  
    <groupId>jstl</groupId>  
    <artifactId>jstl</artifactId>  
    <version>${jstl.version}</version>  
  </dependency>  
  <dependency>  
    <groupId>javax.servlet</groupId>  
    <artifactId>servlet-api</artifactId>  
    <version>${servlet.version}</version>  
  </dependency>  
  <dependency>  
    <groupId>javax.servlet</groupId>  
    <artifactId>jsp-api</artifactId>  
    <version>${jsp.version}</version>  
  </dependency>  
</dependencies>  



src/main/java **/*.xml src/main/resources **/*.xml **/*.properties

<!--tomcat插件-->  
  <plugins>  
    <plugin>  
      <groupId>org.apache.tomcat.maven</groupId>  
      <artifactId>tomcat7-maven-plugin</artifactId>  
      <version>${tomcat.version}</version>  
    </plugin>  
  </plugins>  


SqlMapperClient.xml



db.properties

jdbc.driver=com.mysql.jdbc.Driver
jdbc.url=jdbc:mysql://localhost:3306/mytest?characterEncoding=utf-8
jdbc.username=root
jdbc.password=root

applicationContext-dao.xml


http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.2.xsd http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.2.xsd">

<!--配置解析properties文件的工具类-->  
<context:property-placeholder location="classpath:resource/db.properties"/>

<!--配置数据源-->  
<bean id="dataSource" class="com.alibaba.druid.pool.DruidDataSource">  
    <property name="url" value="${jdbc.url}"/>  
    <property name="username" value="${jdbc.username}"/>  
    <property name="password" value="${jdbc.password}"/>  
    <property name="driverClassName" value="${jdbc.driver}"/>  
    <property name="maxActive" value="10"/>  
    <property name="minIdle" value="5"/>  
</bean>

<!--创建mybatis的上下文对象-->  
<bean class="org.mybatis.spring.SqlSessionFactoryBean">  
    <property name="dataSource" ref="dataSource"/>  
    <property name="configLocation" value="classpath:mybatis/SqlMapperClient.xml"/>  
</bean>

<!--扫描mybatis的接口与映射配置文件-->  
<bean class="org.mybatis.spring.mapper.MapperScannerConfigurer">  
    <property name="basePackage" value="com.ldf.mapper"/>  
</bean>  

applicationContext-service.xml


http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.2.xsd http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.2.xsd">

<!--注册扫描@Service的包-->  
<context:component-scan base-package="com.ldf.service"/>

applicationContext-trans.xml


http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.2.xsd http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-3.2.xsd http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-3.2.xsd">

<!--配置事务管理器-->  
<bean id="transactionManager"  
      class="org.springframework.jdbc.datasource.DataSourceTransactionManager">  
    <property name="dataSource" ref="dataSource"/>  
</bean>

<!--配置事务传播行为-->  
<tx:advice id="advice" transaction-manager="transactionManager">  
    <tx:attributes>  
        <tx:method name="update\*" propagation="REQUIRED" />  
        <tx:method name="delete\*" propagation="REQUIRED" />  
        <tx:method name="insert\*" propagation="REQUIRED" />  
        <!-- <tx:method name="\*" propagation="REQUIRED" /> -->  
    </tx:attributes>  
</tx:advice>

<!-- 配置拦截service -->  
<aop:config>  
    <aop:advisor advice-ref="advice"  
                 pointcut="execution(\* com.ldf.service.\*.\*(..))" />  
</aop:config>  

springMvc.xml


http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.2.xsd http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc-3.2.xsd http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.2.xsd">

<!-- 组建扫描,扫描带有注解的类 -->  
<context:component-scan base-package="com.ldf.controller"/>

<!-- annotation-driven:默认创建了多个对象:RequestMappingHandlerMapping,RequestMappingHandlerAdapter  
    也就提供对json格式支持  
 -->  
<mvc:annotation-driven/>

<!-- 配置视图解析器 -->  
<bean class="org.springframework.web.servlet.view.InternalResourceViewResolver">  
    <property name="prefix" value="/WEB-INF/jsp/"></property>  
    <property name="suffix" value=".jsp"></property>  
</bean>

<!--静态资源映射-->  
<mvc:resources mapping="/css/\*\*" location="/WEB-INF/css/"/>  
<mvc:resources mapping="/js/\*\*" location="/WEB-INF/js/"/>  

web.xml


http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app\_2\_5.xsd" id="WebApp\_ID" version="2.5">


contextConfigLocation classpath:spring/applicationContext-*.xml
org.springframework.web.context.ContextLoaderListener


springmvc org.springframework.web.servlet.DispatcherServlet contextConfigLocation classpath:spring/springmvc.xml 1
springmvc /


encoding org.springframework.web.filter.CharacterEncodingFilter encoding utf-8
encoding /*


index.html index.htm index.jsp default.html default.htm default.jsp