maven 集成spring ,mybatis

  maven工程分模块项目可以模块与模块之间的耦合度降低,各模块之间的联系就没有那么的紧密。通常情况下为了打包方便,建立一个父类的模块。这样打包发布的时候就不用一个个模块打包过去,只有父类的模块手动打包下就可以了,

工程如下图所示:

其中book-parent为父类模块,book-core持久层,book-service为服务层,book-web的可视化层 ,既分别对应mvc中的相应层。

一、book-core

1、添加包支持,pom.xml配置如下:

<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/xsd/maven-4.0.0.xsd">
	<modelVersion>4.0.0</modelVersion>

	<artifactId>book-core</artifactId>
	<packaging>jar</packaging>

	<parent>
		<groupId>com.myWebApp</groupId>
		<artifactId>book-parent</artifactId>
		<version>0.0.1-SNAPSHOT</version>
		<relativePath>../book-parent/pom.xml</relativePath>
	</parent>

	<name>book-core</name>
<!--由于使用父类因此配置如下-->
	<properties>
		<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
	</properties>

	<dependencies>
		<dependency>
			<groupId>org.hibernate</groupId>
			<artifactId>hibernate-core</artifactId>
		</dependency>

		<dependency>
			<groupId>org.apache.logging.log4j</groupId>
			<artifactId>log4j-core</artifactId>
		</dependency>

		<dependency>
			<groupId>org.slf4j</groupId>
			<artifactId>slf4j-log4j12</artifactId>
		</dependency>

		<dependency>
			<groupId>com.google.code.gson</groupId>
			<artifactId>gson</artifactId>
		</dependency>
		<dependency>
			<groupId>org.javassist</groupId>
			<artifactId>javassist</artifactId>
		</dependency>

		<dependency>
			<groupId>org.springframework</groupId>
			<artifactId>spring-core</artifactId>

		</dependency>
		<dependency>
			<groupId>org.springframework</groupId>
			<artifactId>spring-context</artifactId>
		</dependency>

		<dependency>
			<groupId>org.springframework</groupId>
			<artifactId>spring-test</artifactId>

		</dependency>

		<dependency>
			<groupId>org.springframework</groupId>
			<artifactId>spring-aop</artifactId>

		</dependency>

		<dependency>
			<groupId>org.springframework</groupId>
			<artifactId>spring-beans</artifactId>

		</dependency>

		<dependency>
			<groupId>org.springframework</groupId>
			<artifactId>spring-orm</artifactId>

		</dependency>
		<dependency>
				<groupId>org.springframework</groupId>
				<artifactId>spring-test</artifactId>
			</dependency>
		<dependency>
			<groupId>org.springframework</groupId>
			<artifactId>spring-aspects</artifactId>

		</dependency>

		<dependency>
			<groupId>org.apache.commons</groupId>
			<artifactId>commons-dbcp2</artifactId>

		</dependency>

		<dependency>
			<groupId>mysql</groupId>
			<artifactId>mysql-connector-java</artifactId>
		</dependency>
		<dependency>
			<groupId>junit</groupId>
			<artifactId>junit</artifactId>
		</dependency>
		<dependency>
			<groupId>org.mybatis</groupId>
			<artifactId>mybatis</artifactId>
		</dependency>
		<dependency>
			<groupId>javax.persistence</groupId>
			<artifactId>persistence-api</artifactId>
		</dependency>
		<dependency>
			<groupId>org.mybatis</groupId>
			<artifactId>mybatis-spring</artifactId>
		</dependency>
		<dependency>
			<groupId>com.google.code.gson</groupId>
			<artifactId>gson</artifactId>
		</dependency>
		<dependency>
			<groupId>commons-dbcp</groupId>
			<artifactId>commons-dbcp</artifactId>
			<version>1.4</version>
		</dependency>

	</dependencies>
	<build>
		<plugins>
			<plugin>
				<groupId>org.mybatis.generator</groupId>
				<artifactId>mybatis-generator-maven-plugin</artifactId>
				<version>1.3.2</version>
				<configuration>
					<verbose>true</verbose>
					<overwrite>true</overwrite>
				</configuration>
			</plugin>
		</plugins>
	</build>
</project>

  父类pom.xml配置如下:

<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/xsd/maven-4.0.0.xsd">
	<modelVersion>4.0.0</modelVersion>

	<groupId>com.myWebApp</groupId>
	<artifactId>book-parent</artifactId>
	<version>0.0.1-SNAPSHOT</version>
	<packaging>pom</packaging>

	<name>book-parent</name>
	<url>http://maven.apache.org</url>
	<modules>
		<module>../book-core</module>
		<module>../book-service</module>
		<module>../book-web</module>
	</modules>

	<properties>
		<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
	</properties>
	<dependencyManagement>
		<dependencies>
			<dependency>
				<groupId>org.hibernate</groupId>
				<artifactId>hibernate-core</artifactId>
				<version>4.2.1.Final</version>
			</dependency>

			<dependency>
				<groupId>org.apache.logging.log4j</groupId>
				<artifactId>log4j-core</artifactId>
				<version>2.0</version>
			</dependency>

			<dependency>
				<groupId>org.slf4j</groupId>
				<artifactId>slf4j-log4j12</artifactId>
				<version>1.6.1</version>
			</dependency>

			<dependency>
				<groupId>com.google.code.gson</groupId>
				<artifactId>gson</artifactId>
				<version>2.2.4</version>
			</dependency>

			<dependency>
				<groupId>javax.persistence</groupId>
				<artifactId>persistence-api</artifactId>
				<version>1.0.2</version>
			</dependency>
			<dependency>
				<groupId>org.javassist</groupId>
				<artifactId>javassist</artifactId>
				<version>3.15.0-GA</version>
			</dependency>

			<!-- <dependency> <groupId>org.apache.logging.log4j</groupId> <artifactId>log4j-core</artifactId>
				<version>2.0-beta9</version> </dependency> -->
			<!-- <dependency> <groupId>com.jolbox</groupId> <artifactId>bonecp</artifactId>
				<version>0.8.0.RELEASE</version> </dependency> -->

			<dependency>
				<groupId>org.springframework</groupId>
				<artifactId>spring-core</artifactId>
				<version>4.0.6.RELEASE</version>
			</dependency>
			<dependency>
				<groupId>org.springframework</groupId>
				<artifactId>spring-context</artifactId>
				<version>4.0.6.RELEASE</version>
			</dependency>

			<dependency>
				<groupId>org.springframework</groupId>
				<artifactId>spring-test</artifactId>
				<version>4.0.6.RELEASE</version>
			</dependency>

			<dependency>
				<groupId>org.springframework</groupId>
				<artifactId>spring-aop</artifactId>
				<version>4.0.6.RELEASE</version>
			</dependency>

			<dependency>
				<groupId>org.springframework</groupId>
				<artifactId>spring-beans</artifactId>
				<version>4.0.6.RELEASE</version>
			</dependency>

			<dependency>
				<groupId>org.springframework</groupId>
				<artifactId>spring-orm</artifactId>
				<version>4.1.3.RELEASE</version>
			</dependency>

			<dependency>
				<groupId>org.springframework</groupId>
				<artifactId>spring-aspects</artifactId>
				<version>4.0.6.RELEASE</version>
			</dependency>
			<dependency>
				<groupId>org.springframework</groupId>
				<artifactId>spring-web</artifactId>
				<version>4.0.6.RELEASE</version>
			</dependency>

			<dependency>
				<groupId>org.apache.commons</groupId>
				<artifactId>commons-dbcp2</artifactId>
				<version>2.0.1</version>
			</dependency>

			<dependency>
				<groupId>mysql</groupId>
				<artifactId>mysql-connector-java</artifactId>
				<version>5.1.6</version>
			</dependency>

			<dependency>
				<groupId>junit</groupId>
				<artifactId>junit</artifactId>
				<version>4.11</version>
				<scope>test</scope>
			</dependency>

			<dependency>
				<groupId>com.google.code.gson</groupId>
				<artifactId>gson</artifactId>
				<version>2.2.4</version>
			</dependency>

			<!-- web jar -->

			<!-- 依懒users-core -->
			<!-- <dependency> <groupId>com.rui.user</groupId> <artifactId>users-core</artifactId>
				<version>0.0.1-SNAPSHOT</version> </dependency> -->

			<dependency>
				<groupId>javax.servlet</groupId>
				<artifactId>javax.servlet-api</artifactId>
				<version>3.0.1</version>
				<scope>provided</scope>
			</dependency>

			<dependency>
				<groupId>org.springframework</groupId>
				<artifactId>spring-webmvc</artifactId>
				<version>4.0.6.RELEASE</version>
			</dependency>

			<!-- <dependency> <groupId>org.springframework</groupId> <artifactId>spring-web</artifactId>
				<version>4.0.6.RELEASE</version> </dependency> -->
			<!-- <dependency> <groupId>org.codehaus.jackson</groupId> <artifactId>jackson-core-asl</artifactId>
				<version>1.9.13</version> </dependency> -->
			<dependency>
				<groupId>org.codehaus.jackson</groupId>
				<artifactId>jackson-mapper-asl</artifactId>
				<version>1.9.13</version>
			</dependency>
			<dependency>
				<groupId>org.mybatis</groupId>
				<artifactId>mybatis</artifactId>
				<version>3.2.4</version>
			</dependency>

			<dependency>
				<groupId>org.mybatis</groupId>
				<artifactId>mybatis-spring</artifactId>
				<version>1.2.2</version>
			</dependency>

			<dependency>
				<groupId>javax.servlet.jsp.jstl</groupId>
				<artifactId>jstl-api</artifactId>
				<version>1.2</version>
			</dependency>
			<dependency>
				<groupId>com.myWebApp</groupId>
				<artifactId>book-core</artifactId>
				<version>0.0.1-SNAPSHOT</version>
			</dependency>
			<dependency>
				<groupId>com.myWebApp</groupId>
				<artifactId>book-service</artifactId>
				<version>0.0.1-SNAPSHOT</version>
			</dependency>

		</dependencies>
	</dependencyManagement>

	<build>
		<pluginManagement>
			<plugins>
				<plugin>
					<groupId>org.apache.maven.plugins</groupId>
					<artifactId>maven-source-plugin</artifactId>
					<version>2.4</version>
					<executions>
						<execution>
							<goals>
								<goal>jar-no-fork</goal>
							</goals>
						</execution>
					</executions>
				</plugin>
			</plugins>
		</pluginManagement>
	</build>
</project>

  注意:有些包是多余的,

2、实体类User代码如下:

package com.mr.cheng.entity;

public class User {
    private Integer id;

    private String descn;

    private String username;

    private String password;

    public Integer getId() {
        return id;
    }

    public void setId(Integer id) {
        this.id = id;
    }

    public String getDescn() {
        return descn;
    }

    public void setDescn(String descn) {
        this.descn = descn == null ? null : descn.trim();
    }

    public String getUsername() {
        return username;
    }

    public void setUsername(String username) {
        this.username = username == null ? null : username.trim();
    }

    public String getPassword() {
        return password;
    }

    public void setPassword(String password) {
        this.password = password == null ? null : password.trim();
    }
}

3、User实体类对已的Dao与xml文件代码如下:

<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd" >
<mapper namespace="com.mr.cheng.dao.IUserDao" >
  <resultMap id="BaseResultMap" type="com.mr.cheng.entity.User" >
    <id column="Id" property="id" jdbcType="INTEGER" />
    <result column="descn" property="descn" jdbcType="VARCHAR" />
    <result column="username" property="username" jdbcType="VARCHAR" />
    <result column="password" property="password" jdbcType="VARCHAR" />
  </resultMap>
  <delete id="deleteByPrimaryKey" parameterType="java.lang.Integer" >
    delete from users
    where Id = #{id,jdbcType=INTEGER}
  </delete>
  <insert id="insert" parameterType="com.mr.cheng.entity.User" >
    insert into users (Id, descn, username,
      password)
    values (#{id,jdbcType=INTEGER}, #{descn,jdbcType=VARCHAR}, #{username,jdbcType=VARCHAR},
      #{password,jdbcType=VARCHAR})
  </insert>
  <update id="updateByPrimaryKey" parameterType="com.mr.cheng.entity.User" >
    update users
    set descn = #{descn,jdbcType=VARCHAR},
      username = #{username,jdbcType=VARCHAR},
      password = #{password,jdbcType=VARCHAR}
    where Id = #{id,jdbcType=INTEGER}
  </update>
  <select id="selectByPrimaryKey" resultMap="BaseResultMap" parameterType="java.lang.Integer" >
    select Id, descn, username, password
    from users
    where Id = #{id,jdbcType=INTEGER}
  </select>
  <select id="selectAll" resultMap="BaseResultMap" >
    select Id, descn, username, password
    from users
  </select>
</mapper>

  

package com.mr.cheng.dao;

import com.mr.cheng.entity.User;

import java.util.List;

import org.springframework.stereotype.Component;
/**
 * 注意注解@Component必须有,也可以用Service或者Controller代替
 * @author zwc
 *
 */
@Component
public interface IUserDao {
    int deleteByPrimaryKey(Integer id);

    int insert(User record);

    User selectByPrimaryKey(Integer id);

    List<User> selectAll();

    int updateByPrimaryKey(User user);
}

4、spring-mybatis.xml配置如下:

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
	xmlns:context="http://www.springframework.org/schema/context"
	xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:tx="http://www.springframework.org/schema/tx"
	xsi:schemaLocation="http://www.springframework.org/schema/beans
    http://www.springframework.org/schema/beans/spring-beans-4.0.xsd
    http://www.springframework.org/schema/tx
	http://www.springframework.org/schema/tx/spring-tx-4.0.xsd
    http://www.springframework.org/schema/context
    http://www.springframework.org/schema/context/spring-context-4.0.xsd">

<!-- 数据库连接配置 -->
	<bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource">
		<property name="driverClassName" value="com.mysql.jdbc.Driver">
		</property>
		<property name="url" value="jdbc:mysql://localhost:3306/hibernate"></property>
		<property name="username" value="root" />
		<property name="password" value="root" />
	</bean>
	<!-- spring集成MyBaits -->
	<bean id="sqlSessionFactory" class="org.mybatis.spring.SqlSessionFactoryBean">
		<property name="dataSource" ref="dataSource" />
		<!-- 自动扫描entity目录, 省掉Configuration.xml里的手工配置 -->
		<property name="mapperLocations" value="classpath:com/mr/cheng/xml/*.xml" />
	</bean>
	<!-- 使dao与xml文件一一对应 ,注意dao接口必须使用注解 -->
	<bean class="org.mybatis.spring.mapper.MapperScannerConfigurer">
		<property name="basePackage" value="com.mr.cheng.dao" />
		<property name="sqlSessionFactoryBeanName" value="sqlSessionFactory" />
	</bean>
	<!-- 添加注解支持 -->
	<tx:annotation-driven />
</beans>

5、测试类如下:

package com.mr.cheng.test;

import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;

import com.mr.cheng.dao.IUserDao;
import com.mr.cheng.entity.User;

public class MyAppTest {
	@Autowired
	private IUserDao iUserDao;

	public void addUserTest(){
		User user = new User();
		user.setDescn("111");
		user.setPassword("password");
		user.setUsername("cheng");
		iUserDao.insert(user);
	}

}

  

二、book-service

1、book-service是服务层,它对外提供接口。控制层不需要知道具体的实现,只有根据相应的接口就可以去选择他要想的服务。

接口代码如下:

package com.mr.cheng.biz;

import java.util.List;

import org.springframework.stereotype.Component;

import com.mr.cheng.entity.User;

@Component
public interface UserBizDao {
    int deleteByPrimaryKey(Integer id);

    int insert(User record);

    User selectByPrimaryKey(Integer id);

    List<User> selectAll();

    int updateByPrimaryKey(User user);
}

实现类:

package com.mr.cheng.biz.impl;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.mr.cheng.biz.UserBizDao;
import com.mr.cheng.dao.IUserDao;
import com.mr.cheng.entity.User;

@Service
public class UserBizDaoImpl implements UserBizDao {
    @Autowired
    private IUserDao iUserDao;
    public int deleteByPrimaryKey(Integer id) {
        iUserDao.deleteByPrimaryKey(id);
        return 0;
    }

    public int insert(User record) {
        iUserDao.insert(record);
        return 0;
    }

    public User selectByPrimaryKey(Integer id) {
        return iUserDao.selectByPrimaryKey(id);
    }

    public List<User> selectAll() {
        return iUserDao.selectAll();
    }

    public int updateByPrimaryKey(User user) {
        iUserDao.updateByPrimaryKey(user);
        return 0;
    }

}

2、配置文件:

spring-service如下:

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
    xmlns:context="http://www.springframework.org/schema/context"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:tx="http://www.springframework.org/schema/tx"
    xsi:schemaLocation="http://www.springframework.org/schema/beans
    http://www.springframework.org/schema/beans/spring-beans-4.0.xsd
    http://www.springframework.org/schema/tx
    http://www.springframework.org/schema/tx/spring-tx-4.0.xsd
    http://www.springframework.org/schema/context
    http://www.springframework.org/schema/context/spring-context-4.0.xsd">
    <tx:annotation-driven />
     <context:component-scan base-package="com.mr.cheng.biz.impl.*" />
</beans>

pom.xml代码如下:

<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/xsd/maven-4.0.0.xsd">
  <modelVersion>4.0.0</modelVersion>

  <artifactId>book-service</artifactId>
  <packaging>jar</packaging>

  <parent>
      <artifactId>book-parent</artifactId>
      <groupId>com.myWebApp</groupId>
      <version>0.0.1-SNAPSHOT</version>
      <relativePath>../book-parent/pom.xml</relativePath>
  </parent>

  <name>book-service</name>

  <properties>
    <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
  </properties>

  <dependencies>
    <dependency>
        <groupId>com.myWebApp</groupId>
        <artifactId>book-core</artifactId>
    </dependency>
    <dependency>
            <groupId>junit</groupId>
            <artifactId>junit</artifactId>
        </dependency>
  </dependencies>

        <build>
        <plugins>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-source-plugin</artifactId>
            </plugin>
        </plugins>
    </build>
</project>

三、book-web模块

1、book-web是web项目,在这个模块项目中他有页面以及相应的控制层组成。页面既是mvc中的视图 ,同事也包含了mvc中的控制层。

控制层代码:

package com.mr.cheng.controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;

import com.mr.cheng.biz.UserBizDao;
import com.mr.cheng.entity.User;

@Controller
@RequestMapping("/userController.do")
public class UserController {
    @Autowired
    private UserBizDao userBizDao;
    @RequestMapping("/login")
    public String login(){
        User user = new User();
        user.setDescn("1111");
        user.setUsername("abc");
        user.setPassword("pass");
        userBizDao.insert(user);
        return "success";
    }
}

spring-web配置:

<?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:p="http://www.springframework.org/schema/p"
    xmlns:context="http://www.springframework.org/schema/context" xmlns:tx="http://www.springframework.org/schema/tx"
    xmlns:mvc="http://www.springframework.org/schema/mvc" xmlns:aop="http://www.springframework.org/schema/aop"
    xmlns:tool="http://www.springframework.org/schema/tool"
    xsi:schemaLocation="http://www.springframework.org/schema/beans
                        http://www.springframework.org/schema/beans/spring-beans-4.0.xsd
                        http://www.springframework.org/schema/context
                        http://www.springframework.org/schema/context/spring-context-4.0.xsd
                        http://www.springframework.org/schema/tx
                        http://www.springframework.org/schema/tx/spring-tx-4.0.xsd
                        http://www.springframework.org/schema/aop
                        http://www.springframework.org/schema/aop/spring-aop-4.0.xsd
                        http://www.springframework.org/schema/tool
                        http://www.springframework.org/schema/tool/spring-tool-4.0.xsd
                         http://www.springframework.org/schema/mvc
                        http://www.springframework.org/schema/mvc/spring-mvc-4.0.xsd">

    <context:component-scan base-package="com.mr.cheng.controller" />
</beans>

spring-mvc配日志:

<?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:p="http://www.springframework.org/schema/p"
    xmlns:context="http://www.springframework.org/schema/context" xmlns:tx="http://www.springframework.org/schema/tx"
    xmlns:mvc="http://www.springframework.org/schema/mvc" xmlns:aop="http://www.springframework.org/schema/aop"
    xmlns:tool="http://www.springframework.org/schema/tool"
    xsi:schemaLocation="http://www.springframework.org/schema/beans
                        http://www.springframework.org/schema/beans/spring-beans-4.0.xsd
                        http://www.springframework.org/schema/context
                        http://www.springframework.org/schema/context/spring-context-4.0.xsd
                        http://www.springframework.org/schema/tx
                        http://www.springframework.org/schema/tx/spring-tx-4.0.xsd
                        http://www.springframework.org/schema/aop
                        http://www.springframework.org/schema/aop/spring-aop-4.0.xsd
                        http://www.springframework.org/schema/tool
                        http://www.springframework.org/schema/tool/spring-tool-4.0.xsd
                         http://www.springframework.org/schema/mvc
                        http://www.springframework.org/schema/mvc/spring-mvc-4.0.xsd">

    <!-- 启用spring mvc 注解 -->
    <!-- 为了让spring容器识别注解配日志 -->
    <context:annotation-config />
<!--     <mvc:annotation-driven />
    <mvc:default-servlet-handler /> -->

    <!-- 注解扫描 -->
    <context:component-scan base-package="com.mr.cheng.controller" />
    <!-- <context:component-scan base-package="**.controller.**" /> -->

    <!-- 静态资源访问 -->
    <mvc:resources mapping="/front/**" location="/front/" />

    <!--页面视图层信息 -->
    <bean id="viewResolver"
        class="org.springframework.web.servlet.view.InternalResourceViewResolver">
        <property name="viewClass"
            value="org.springframework.web.servlet.view.JstlView"></property>
        <property name="prefix" value="/"></property> <!--页面的前辍名 -->
        <property name="suffix" value=".jsp"></property> <!--页面的后辍名 -->
    </bean>
<!--     <bean
        class="org.springframework.web.servlet.mvc.annotation.DefaultAnnotationHandlerMapping">
        <property name="order" value="0" />
    </bean>
        <bean class="org.springframework.web.servlet.mvc.annotation.AnnotationMethodHandlerAdapter" /> -->
<mvc:annotation-driven/>
</beans>

web.xml配置:

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

    <description>hello</description>
    <display-name>rui Java Deploy V1.1.0</display-name>

    <context-param>
        <param-name>log4jConfigLocation</param-name>
        <!-- /WEB-INF/classes/ -->
        <param-value>config/properties/log4j.properties</param-value>
    </context-param>

    <!-- <context-param> <param-name>contextConfigLocation</param-name> <param-value>/WEB-INF/classes/config/spring/**/*.xml</param-value>
        </context-param> -->

    <context-param>
        <param-name>contextConfigLocation</param-name>
        <param-value>
<!--         classpath*:config/spring/spring-config.xml
      classpath*:config/spring/user-db.xml
      classpath*:config/spring/dao/user-dao.xml
      classpath*:config/spring/services/user-services.xml
      classpath*:config/spring/user-web.xml
       classpath*:config/springmvc/spring-servlet.xml-->
       classpath*:config/spring-web.xml
       classpath*:config/spring-service.xml
       classpath*:config/spring-mybatis.xml
      </param-value>
    </context-param>

    <servlet>
        <servlet-name>springMvc</servlet-name>
        <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
        <init-param>
            <param-name>ContextConfigLocation</param-name>
            <param-value>classpath:config/spring-mvc.xml</param-value>
        </init-param>
        <load-on-startup>1</load-on-startup>
    </servlet>
    <servlet-mapping>
        <servlet-name>springMvc</servlet-name>
        <url-pattern>/*</url-pattern>
    </servlet-mapping>

    <!-- 编码 -->
    <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>

    <!-- 解决hibernate 懒加载异常 OpenSessionInViewFilter openSessionInView -->
    <!-- <filter>
        <filter-name>openSessionInView</filter-name>
        <filter-class>org.springframework.orm.hibernate3.support.OpenSessionInViewFilter</filter-class>
    </filter>

    <filter-mapping>
        <filter-name>openSessionInView</filter-name>
        <url-pattern>/*</url-pattern>
    </filter-mapping> -->

    <!-- 监听 -->
    <listener>
        <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
    </listener>
    <welcome-file-list>
        <welcome-file>index.jsp</welcome-file>
    </welcome-file-list>

</web-app>

时间: 2024-10-30 09:59:25

maven 集成spring ,mybatis的相关文章

Maven 整合 Spring + MyBatis

Maven 整合 Spring + MyBatis 存记录备忘,根据网上搜的孙宇老师的一个视频整理而成 一.搭建工程 使用Intellij搭建工程(由于eclipse对maven支持不如Intellij,所以选用Intellij,eclipse搭建工程相对复杂,可以百度相关文章). 搭建工程十分简单,建好之后直接进入mybatis 与 Spring整合. 二.整合Mybatis 工程搭建好之后已经包含以下jar包,版本为4.1.1.RELEASE 1 <dependency> 2 <gr

springmvc学习总结(二) -- maven+springmvc+spring+mybatis+mysql详细搭建整合过程讲解

@[email protected] 写在最前 之前分享过下面这几篇: mybatis学习笔记(五) -- maven+spring+mybatis从零开始搭建整合详细过程(上)(附demo和搭建过程遇到的问题解决方法) mybatis学习笔记(六) -- maven+spring+mybatis从零开始搭建整合详细过程(下) springmvc学习笔记(一) -- 从零搭建,基础入门 这一篇,在这些练习的基础上,将它们整合在一起! 搭建步骤如下 一.新建maven项目,配置环境,测试是否配置成

第一章 maven+springmvc+spring+mybatis+velocity整合

一.ssmm简介 ssmm是当下企业最常用的开发框架架构 maven:管理项目jar包,构建项目 spring:IOC容器,事务管理 springmvc:mvc框架 myBatis:持久层框架 velocity:前端视图模板(相较于jsp,速度非常快,而且不需要占据jvm的永久代内存) 上述这些框架再加上版本控制工具(git).自动化部署工具(jenkins),就组成了当下中大型企业最常用的项目开发部署架构:以上各种框架以后我也会依次做笔记去写的,所以在下边不会做详细介绍.还有,在以下的整合过程

sharding-jdbc集成spring+mybatis分表分库

maven: <?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.

大型分布式项目项目实战Springmvc+Spring+Mybatis+Maven+CMS+Redis+Solr+Linux+Nginx+单点登录、分布式缓存、负载均衡视频课程

* { font-family: "Microsoft YaHei" !important } h1 { color: #FF0 } 15套java架构师.集群.高可用.高可扩 展.高性能.高并发.性能优化.Spring boot.Redis.ActiveMQ.Nginx.Mycat.Netty.Jvm大型分布 式项目实战视频教程 视频课程包含: 高级Java架构师包含:Spring boot.Spring  cloud.Dubbo.Redis.ActiveMQ.Nginx.Mycat

maven spring mybatis配置注意点

以下对使用maven配置spring+mybatis项目时,完成基本的配置需要添加的一些信息进行说明.仅对mybatis部分进行列举. maven添加mybatis支持 <!-- mybatis核心包 –> <dependency>         <groupId>org.mybatis</groupId>         <artifactId>mybatis</artifactId>         <version>

Maven构建SpringMVC+Mybatis项目

1.创建Maven项目时,起始是没有src/main/java.src/test/java.src/test/resources,需要修改一些配置之后,自动就会创建出来: 2.开始引入Spring+MyBatis相应的jar包,Maven的好处就是:只需要在pom.xml配置文件中写上相应的包依赖语句,该项目就会自动生成相应的jar包: 3.引入相应的配置文件: spring.xml----spring框架的配置文件: [(1).自动注入注解的配置: <!-- 自动扫描(自动注入) ,扫描相应的

Maven 结合 Spring profile对不同的部署环境打包部署

这是一个草鸡鸡冻人心的时刻,搞了2天终于搞定了,麻麻再也不用担心我部署出错了!!!!!!! 所有profile,spring和maven的,定义均要一致,否则,自己运行看看. 首先,先来讲下spring的profile功能,这个是方便项目的各种环境分离(开发.测试.生产),简单介绍下如何使用. 在beans中定义环境代码,项目中,我在beans.xml里定义 1 <beans profile="develop,test,product"></beans> 在数据

SpringMVC+Spring+Mybatis -- 集成之旅

准备 首先介绍一下,我的工具使用的是STS, 需要的童鞋可以到官网下载:http://spring.io/tools/sts/all 使用STS是因为她集成了Maven进行 “包“ 管理以及自带 Web server 方便部署(不用配置啦~),个人感觉还是挺方便的.如果大家想要自己配置Tomcat,也未尝不可 :) 我下载的是压缩包的STS,下载完成后解压缩 -> 启动STS.exe ->指定 workspace ->创建Maven项目 -> 选择建立 webapp 项目. 等待片