`
liu_jiaqiang
  • 浏览: 20672 次
  • 性别: Icon_minigender_1
  • 来自: 北京
社区版块
存档分类
最新评论

maven搭建springmvc+spring+mybatis实例

    博客分类:
  • java
阅读更多


maven管理的springmvc+spring+mybatis,
还用到了阿里巴巴的 fastjson和druid连接池,配置文件如下
pom.xml文件

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.dahafo.demo</groupId>
<name>um</name>
<packaging>war</packaging>
<version>1.0.0-BUILD-SNAPSHOT</version>
<properties>
<java-version>1.7</java-version>
<org.springframework-version>3.2.3.RELEASE</org.springframework-version>
<org.aspectj-version>1.6.10</org.aspectj-version>
<org.slf4j-version>1.6.6</org.slf4j-version>
</properties>
<dependencies>
<!-- Spring -->
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-context</artifactId>
<version>${org.springframework-version}</version>
<exclusions>
<!-- Exclude Commons Logging in favor of SLF4j -->
<exclusion>
<groupId>commons-logging</groupId>
<artifactId>commons-logging</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-webmvc</artifactId>
<version>${org.springframework-version}</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-jdbc</artifactId>
<version>${org.springframework-version}</version>
</dependency>

<!-- AspectJ -->
<dependency>
<groupId>org.aspectj</groupId>
<artifactId>aspectjrt</artifactId>
<version>${org.aspectj-version}</version>
</dependency>

<!-- Logging -->
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
<version>${org.slf4j-version}</version>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>jcl-over-slf4j</artifactId>
<version>${org.slf4j-version}</version>
<scope>runtime</scope>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-log4j12</artifactId>
<version>${org.slf4j-version}</version>
<scope>runtime</scope>
</dependency>
<dependency>
<groupId>log4j</groupId>
<artifactId>log4j</artifactId>
<version>1.2.15</version>
<exclusions>
<exclusion>
<groupId>javax.mail</groupId>
<artifactId>mail</artifactId>
</exclusion>
<exclusion>
<groupId>javax.jms</groupId>
<artifactId>jms</artifactId>
</exclusion>
<exclusion>
<groupId>com.sun.jdmk</groupId>
<artifactId>jmxtools</artifactId>
</exclusion>
<exclusion>
<groupId>com.sun.jmx</groupId>
<artifactId>jmxri</artifactId>
</exclusion>
</exclusions>
<scope>runtime</scope>
</dependency>

<!-- @Inject -->
<dependency>
<groupId>javax.inject</groupId>
<artifactId>javax.inject</artifactId>
<version>1</version>
</dependency>

<!-- Servlet -->
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>servlet-api</artifactId>
<version>2.5</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>javax.servlet.jsp</groupId>
<artifactId>jsp-api</artifactId>
<version>2.1</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>jstl</artifactId>
<version>1.2</version>
</dependency>
<!-- mybatis -->
    <dependency>
    <groupId>org.mybatis</groupId>
<artifactId>mybatis</artifactId>
<version>3.2.1</version>
</dependency>
<dependency>
<groupId>org.mybatis</groupId>
<artifactId>mybatis-spring</artifactId>
<version>1.2.0</version>
</dependency>
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<version>5.1.26</version>
</dependency>



<!-- Test -->
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.7</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>com.alibaba</groupId>
<artifactId>druid</artifactId>
<version>0.2.20</version>
</dependency>

<dependency>
<groupId>org.aspectj</groupId>
<artifactId>aspectjweaver</artifactId>
<version>1.7.2</version>
</dependency>
<dependency>
<groupId>com.alibaba</groupId>
<artifactId>fastjson</artifactId>
<version>1.1.34</version>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-core</artifactId>
<version>2.2.2</version>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-databind</artifactId>
<version>2.2.2</version>
</dependency>
<dependency>
<groupId>commons-fileupload</groupId>
<artifactId>commons-fileupload</artifactId>
<version>1.2.2</version>
</dependency>
</dependencies>









    <build>
        <plugins>
            <plugin>
                <artifactId>maven-eclipse-plugin</artifactId>
                <version>2.9</version>
                <configuration>
                    <additionalProjectnatures>
                        <projectnature>org.springframework.ide.eclipse.core.springnature</projectnature>
                    </additionalProjectnatures>
                    <additionalBuildcommands>
                        <buildcommand>org.springframework.ide.eclipse.core.springbuilder</buildcommand>
                    </additionalBuildcommands>
                    <downloadSources>true</downloadSources>
                    <downloadJavadocs>true</downloadJavadocs>
                </configuration>
            </plugin>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-compiler-plugin</artifactId>
                <version>2.5.1</version>
                <configuration>
                    <source>1.6</source>
                    <target>1.6</target>
                    <compilerArgument>-Xlint:all</compilerArgument>
                    <showWarnings>true</showWarnings>
                    <showDeprecation>true</showDeprecation>
                </configuration>
            </plugin>
            <plugin>
                <groupId>org.codehaus.mojo</groupId>
                <artifactId>exec-maven-plugin</artifactId>
                <version>1.2.1</version>
                <configuration>
                    <mainClass>org.test.int1.Main</mainClass>
                </configuration>
            </plugin>
        </plugins>
    </build>
    <artifactId>demo-um</artifactId>
</project>

web.xml
<?xml version="1.0" encoding="UTF-8"?>
<web-app version="2.5" xmlns="http://java.sun.com/xml/ns/javaee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd">



<!-- The definition of the Root Spring Container shared by all Servlets and Filters -->
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>/WEB-INF/spring/root-context.xml</param-value>
</context-param>
<!-- 用spring Encoding,解决乱码问题 -->
<filter>   
            <filter-name>encodingFilter</filter-name>   
            <filter-class>org.springframework.web.filter.CharacterEncodingFilter</filter-class>   
            <init-param>   
                <param-name>encoding</param-name>   
                <param-value>UTF-8</param-value>   
            </init-param>   
            <init-param>   
                <param-name>forceEncoding</param-name>   
                <param-value>true</param-value>   
            </init-param>   
        </filter>   
         <filter-mapping>   
            <filter-name>encodingFilter</filter-name>   
            <url-pattern>/*</url-pattern>   
        </filter-mapping>
<!-- Creates the Spring Container shared by all Servlets and Filters -->
<listener>
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>

    
   
       
<!-- Processes application requests -->
<servlet>
<servlet-name>appServlet</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
<init-param>
<param-name>contextConfigLocation</param-name>
<param-value>/WEB-INF/spring/appServlet/servlet-context.xml</param-value>
</init-param>
<load-on-startup>1</load-on-startup>
</servlet>

<servlet-mapping>
<servlet-name>appServlet</servlet-name>
<url-pattern>/</url-pattern>
</servlet-mapping>

</web-app>
root-context.xml spring的主配置文件
<?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:context="http://www.springframework.org/schema/context"
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-3.0.xsd
">
    <context:annotation-config />
<context:component-scan base-package="com.dahafo.demo.um" />
<import resource="spring-mybatis.xml"/>
</beans>

servlet-context.xml springmvc的主配置文件
<?xml version="1.0" encoding="UTF-8"?>
<beans:beans xmlns="http://www.springframework.org/schema/mvc"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:beans="http://www.springframework.org/schema/beans"
xmlns:context="http://www.springframework.org/schema/context"
xsi:schemaLocation="http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc.xsd
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">

<!-- DispatcherServlet Context: defines this servlet's request-processing infrastructure -->

<!-- Enables the Spring MVC @Controller programming model -->
<annotation-driven />
<context:component-scan base-package="com.dahafo.demo.um.controller" />

<!-- Handles HTTP GET requests for /resources/** by efficiently serving up static resources in the ${webappRoot}/resources directory -->
<resources mapping="/resources/**" location="/resources/" />
<resources mapping="/css/**" location="/css/" />
<resources mapping="/images/**" location="/images/" />
<resources mapping="/js/**" location="/js/" />

<!-- Jackson转换器 -->
<beans:bean id="mappingJacksonHttpMessageConverter" class="org.springframework.http.converter.json.MappingJackson2HttpMessageConverter" />
<!-- fastjson转换器 -->
<beans:bean id="fastJsonHttpMessageConverter"  class="com.alibaba.fastjson.support.spring.FastJsonHttpMessageConverter"/>
<beans:bean class="org.springframework.web.servlet.mvc.annotation.AnnotationMethodHandlerAdapter"  >
    <beans:property name="messageConverters">
       <beans:list>
          <beans:ref bean="fastJsonHttpMessageConverter" /><!-- json转换器 -->
       </beans:list>
    </beans:property>
</beans:bean>
<!-- Resolves views selected for rendering by @Controllers to .jsp resources in the /WEB-INF/views directory -->
<beans:bean class="org.springframework.web.servlet.view.InternalResourceViewResolver">
<beans:property name="prefix" value="/WEB-INF/views/" />
<beans:property name="suffix" value=".jsp" />
</beans:bean>

<beans:bean id="maxUploadSize" class="org.springframework.web.multipart.commons.CommonsMultipartResolver">
    <beans:property name="maxUploadSize" value="32505856" /><!-- 上传文件大小限制为31M,31*1024*1024 -->
    <beans:property name="maxInMemorySize" value="4096" />
</beans:bean>



</beans:beans>

spring-mybatis.xml  mybatis的配置文件,数据源用 的是阿里巴巴的 druid
<?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:context="http://www.springframework.org/schema/context"
xmlns:tx="http://www.springframework.org/schema/tx"
xmlns:aop="http://www.springframework.org/schema/aop"
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-3.0.xsd
http://www.springframework.org/schema/tx  http://www.springframework.org/schema/tx/spring-tx-3.0.xsd
    http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-3.0.xsd
">
    <!-- 引入属性文件 -->
<context:property-placeholder location="classpath:jdbc.properties" />

<!-- 配置数据源 -->
<bean name="dataSource" class="com.alibaba.druid.pool.DruidDataSource" init-method="init" destroy-method="close">
<property name="url" value="${url}" />
<property name="username" value="${username}" />
<property name="password" value="${password}" />
<property name="initialSize" value="1" />
<property name="maxActive" value="20" />
<property name="minIdle" value="1" />
<property name="maxWait" value="60000" />
<property name="validationQuery" value="${validationQuery}" />
<property name="testOnBorrow" value="false" />
<property name="testOnReturn" value="false" />
<property name="testWhileIdle" value="true" />
<property name="timeBetweenEvictionRunsMillis" value="60000" />
<property name="minEvictableIdleTimeMillis" value="25200000" />
<property name="removeAbandoned" value="true" />
<property name="removeAbandonedTimeout" value="1800" />
<property name="logAbandoned" value="true" />
<property name="filters" value="mergeStat" />
</bean>

<!-- myBatis文件 -->
<bean id="sqlSessionFactory" class="org.mybatis.spring.SqlSessionFactoryBean">
<property name="dataSource" ref="dataSource" />
    <property name="mapperLocations" value="classpath:com/dahafo/demo/um/mapping/*Mapper.xml" />
</bean>

<bean class="org.mybatis.spring.mapper.MapperScannerConfigurer">
<property name="basePackage" value="com.dahafo.demo.um.dao" />
<property name="sqlSessionFactoryBeanName" value="sqlSessionFactory" />
</bean>

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

<!-- 注解方式配置事物 -->
<!-- <tx:annotation-driven transaction-manager="transactionManager" /> -->

<!-- 拦截器方式配置事物 -->
<tx:advice id="transactionAdvice" transaction-manager="transactionManager">
<tx:attributes>
<tx:method name="add*" propagation="REQUIRED" />
<tx:method name="modify*" propagation="REQUIRED" />
<tx:method name="delete*" propagation="REQUIRED" />
<tx:method name="find*" propagation="SUPPORTS" />
<tx:method name="query" propagation="SUPPORTS" />
<tx:method name="search*" propagation="SUPPORTS" />
<tx:method name="*" propagation="SUPPORTS" />
</tx:attributes>
</tx:advice>
<aop:config>
<aop:pointcut id="transactionPointcut" expression="execution(* com.dahafo.demo.um.service.*.*(..))" />
<aop:advisor pointcut-ref="transactionPointcut" advice-ref="transactionAdvice" />
</aop:config>
<!-- 配置druid监控spring jdbc -->
<bean id="druid-stat-interceptor" class="com.alibaba.druid.support.spring.stat.DruidStatInterceptor">
</bean>
<bean id="druid-stat-pointcut" class="org.springframework.aop.support.JdkRegexpMethodPointcut" scope="prototype">
<property name="patterns">
<list>
<value>com.dahafo.demo.um.service.impl</value>
</list>

</property>
</bean>
<aop:config>
<aop:advisor advice-ref="druid-stat-interceptor" pointcut-ref="druid-stat-pointcut" />
</aop:config>
</beans>
分享到:
评论

相关推荐

    springmvc + spring + mybatis + maven整合配置文件

    3. **MyBatis-Spring整合**:使MyBatis与Spring无缝集成,通过Spring的DAO支持自动管理SqlSession和Mapper实例。 **Maven** Maven是一个项目管理和综合工具,通过POM(Project Object Model)文件管理项目的依赖...

    Spring+SpringMVC+Mybatis+Maven+bootstrap+ajax+jQuery整合开发简单的员工后台管理系统

    在本项目中,"Spring+SpringMVC+Mybatis+Maven+bootstrap+ajax+jQuery整合开发简单的员工后台管理系统",我们看到一个基于Java技术栈的Web应用开发实例。这个系统利用了多个核心技术来构建一个功能完备的员工管理...

    SpringMvc+Spring+MyBatis+Maven项目

    这是一个基于Java技术栈的经典组合——SpringMvc、Spring、MyBatis和Maven的项目整合教程。这个项目旨在帮助开发者理解并掌握如何将这些组件有效地集成到一个完整的Web应用程序中。以下将详细介绍这些技术和它们在...

    Spirng+SpringMVC+Maven+Mybatis+MySQL实例

    在这个实例中,开发者首先会使用Eclipse创建一个Maven项目,然后配置Spring、SpringMVC、Mybatis的相关依赖。接着,会在`first_maven_project`这个目录下编写代码,包括配置文件、实体类、DAO接口、Mapper XML文件、...

    SpringMvc+Spring+MyBatis+Maven整合实例

    SpringMvc+Spring+MyBatis+Maven整合实例代码,教程见:http://www.cnblogs.com/NaughtyBaby/p/4754881.html 该教程是通过看: BBS.BTBOYS.COM社区-孙宇. 《SpringMvc+Spring+Mybatis+Maven整合视频教程1》 编写供...

    整合Spring+SpringMVC+Mybatis+Maven+Mysql项目实例

    整合搭建Spring+SpringMVC+Mybatis+Maven+Mysql开发实例

    maven+SpringMvc+mybatis实例

    【maven+SpringMvc+mybatis实例】是一个适合初学者的综合项目,它结合了三个重要的Java开发技术:Maven、SpringMVC和MyBatis。这个实例将帮助你理解如何构建一个完整的Java Web应用程序,从依赖管理到业务逻辑处理。...

    spring+spring mvc+mybatis框架整合实现超市货物管理系统

    在该项目中,我们需要设置相关的Maven或Gradle依赖,确保Spring、Spring MVC和MyBatis等库的引入,并配置数据库连接。 总的来说,"spring+spring mvc+mybatis框架整合实现超市货物管理系统"是一个涵盖后端开发基础...

    Maven+Spring+SpringMVC+Mybatis+Log4j+EasyUI1.3.2+Oracle实例

    这是一个基于Java技术栈的Web应用实例,整合了Maven、Spring、SpringMVC、Mybatis、Log4j和EasyUI1.3.2,并且采用了Oracle数据库。让我们逐一解析这些技术及其在项目中的作用。 **Maven**: Maven是一个项目管理和...

    Spirng+SpringMVC+Maven+Mybatis+MySQL+tomcat实例

    这是一个基于Java技术栈的经典组合——SSM框架(Spring、SpringMVC、Mybatis)与Maven构建工具,以及MySQL数据库和Tomcat应用服务器的实践项目。这个实例将带你深入理解这些技术如何协同工作,构建一个完整的Web应用...

    springmvc+spring+mybatis+maven示例_1.0

    工程名ssmm表示:springmvc+spring+mybatis+maven 框架结构:SpringMVC+Spring+Mybatis 数据库为MySQL 使用Maven管理项目 数据源使用阿里巴巴的温少开发的Druid, 使用Junit4进行单元测试, 使用Log4j管理日志 本例...

    Maven模块项目。整合spring+springmvc+mybatis

    "Maven模块项目"就是这样一个示例,它演示了如何利用Maven的模块化特性,结合Spring、SpringMVC和MyBatis这三大流行Java Web开发框架进行项目整合。下面将详细介绍这些知识点。 首先,Maven是Apache软件基金会开发...

    eclipse下SpringMVC+Maven+Mybatis+MySQL项目搭建

    本项目"eclipse下SpringMVC+Maven+Mybatis+MySQL项目搭建"就是一个典型的Java Web开发实例,它利用了SpringMVC作为控制层,Maven作为项目构建工具,Mybatis作为数据持久层框架,以及MySQL作为数据库管理系统。...

    Maven搭建Spring+Mybatis+SpringMVC+MySql实例

    Maven搭建Spring+Mybatis+SpringMVC+MySql实例,具体效果和过程看博文 http://blog.csdn.net/evankaka/article/details/48785513

    spring+springmvc+mybatis+mysql+maven+eclipse 工程实例

    这是一个基于Java技术栈的Web应用开发实例,涵盖了Spring、SpringMVC、MyBatis、MySQL数据库和Maven构建工具,以及Eclipse IDE的使用。这个工程实例为初学者提供了一个全面的学习平台,让我们逐一深入探讨这些关键...

    【源码+配置教程】Maven3+Spring4+Spring MVC+mybatis3整合实例

    【源码+配置教程】Maven3+Spring4+Spring MVC+mybatis3整合实例是IT领域中一种常见的Web开发框架组合,这个压缩包提供了一套完整的应用实例,旨在帮助开发者快速理解和掌握这些技术的集成与应用。在这个项目中,...

    SSM(Spring+springmvc+mybatis)项目实例.zip

    在这个"SSM(Spring+springmvc+mybatis)项目实例.zip"压缩包中,包含了一个实际的SSM项目和相关的SQL文件,这将有助于我们深入理解SSM框架的工作原理和应用。 首先,Spring框架是整个SSM中的核心,它负责管理对象...

    ssm框架整合(springMVC + spring + MyBatis,)

    1. 创建Maven项目,配置pom.xml文件,引入Spring、SpringMVC、MyBatis及其依赖。 2. 配置Spring的IoC容器,定义Bean,包括数据源、SqlSessionFactory、Mapper接口的扫描等。 3. 配置SpringMVC,设置...

    ZooKeeper+dubbo+springMvc+Mybatis+Mysql 例子

    ZooKeeper+dubbo+springMvc+Mybatis+Mysql实例,项目是由maven搭建的 整合Dubbo\spring\springMvc\Mybatis,整个压缩包中有两个项目分别是提供者和消费,启动方式是打成WAR形式放到tomcat中启动。

Global site tag (gtag.js) - Google Analytics