标签:
一,new maven project --->创建Create a simple project勾选上
修改pom.xml的packaging为pom
Project configuration is not up-to-date with pom.xml. Run Maven->Update Project or use Quick Fix.
这个错误直接maven,update project就好了
二, 在root工程上邮件new maven module,module name为macow-dao。同样建macow-service,macow-common。
macow-web工程不要勾选Create a simple project,点next ,filter中输入web选maven-archetype-webapp,然后直接next,直到完成
三,在root工程上右键,选择maven-->Update project,所有工程都选上,force update(强制更新快照和release版本)和offline(离线)都选上
<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.macow.home.first</groupId> <artifactId>macow-root</artifactId> <version>0.0.1-SNAPSHOT</version> <packaging>pom</packaging> <modules> <module>macow-dao</module> <module>macow-service</module> <module>macow-model</module> <module>macow-web</module> </modules> <properties> <project.version>0.0.1-SNAPSHOT</project.version> <!-- 测试日志 --> <junit.version>4.12</junit.version> <slf4j.version>1.7.7</slf4j.version> <log4j.version>1.2.17</log4j.version> <commons-logging.version>1.1.3</commons-logging.version> <logback.version>1.1.3</logback.version> <!-- Generic properties --> <jedis.version>2.6.0</jedis.version> <java.version>1.6</java.version> <httpclient.version>4.3.6</httpclient.version> <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> <!-- web --> <servlet.version>3.0.1</servlet.version> <servlet-api.version>2.5</servlet-api.version> <jstl.version>1.2</jstl.version> <standard.version>1.1.2</standard.version> <!-- Spring --> <spring.version>3.2.14.RELEASE</spring.version> <fastjson.version>1.2.6</fastjson.version> <jackson2.version>2.3.0</jackson2.version> <jsr311.version>1.1.1</jsr311.version> <aspectj.version>1.7.4</aspectj.version> <cglib.version>2.2.2</cglib.version> <jackson.version>1.9.9</jackson.version> <!-- DAO --> <druid.version>1.0.15</druid.version> <druid-wrapper.version>0.2.9</druid-wrapper.version> <mybatis.version>3.2.8</mybatis.version> <mybatis-spring.version>1.2.2</mybatis-spring.version> <commons-dbcp.version>1.4</commons-dbcp.version> <postgresql.version>9.4-1201-jdbc4</postgresql.version> <pagehelper.version>3.7.6</pagehelper.version> <mapper.version>3.2.2</mapper.version> <persistence-api.version>1.0</persistence-api.version> <oracle.version>11.1.0.7.0</oracle.version> <!-- cxf --> <cxf.version>2.7.17</cxf.version> <!-- jackson_fast --> <jackson_fast.version>2.5.4</jackson_fast.version> <!-- validate --> <javax-validation.version>1.1.0.Final</javax-validation.version> <hibernate-validator.version>4.1.0.Final</hibernate-validator.version> <!-- apatch commons-lang --> <commons.lang.version>2.6</commons.lang.version> <commons-collections>3.1</commons-collections> <commons-fileupload>1.3.1</commons-fileupload> <commons-beanutils>1.8.0</commons-beanutils> </properties> <dependencyManagement> <dependencies> <!-- WEB --> <dependency> <groupId>javax.servlet</groupId> <artifactId>javax.servlet-api</artifactId> <version>${servlet.version}</version> <scope>provided</scope> </dependency> <dependency> <groupId>javax.servlet</groupId> <artifactId>jstl</artifactId> <version>${jstl.version}</version> <scope>provided</scope> </dependency> <dependency> <groupId>taglibs</groupId> <artifactId>standard</artifactId> <version>${standard.version}</version> <scope>provided</scope> </dependency> <!-- Spring --> <dependency> <groupId>org.springframework</groupId> <artifactId>spring-framework-bom</artifactId> <version>${spring.version}</version> <type>pom</type> <scope>import</scope> </dependency> <!-- aspectj --> <dependency> <groupId>org.aspectj</groupId> <artifactId>aspectjweaver</artifactId> <version>${aspectj.version}</version> </dependency> <dependency> <groupId>org.aspectj</groupId> <artifactId>aspectjrt</artifactId> <version>${aspectj.version}</version> </dependency> <!-- cglib --> <dependency> <groupId>cglib</groupId> <artifactId>cglib</artifactId> <version>${cglib.version}</version> </dependency> <!-- DAO相关 --> <dependency> <groupId>org.postgresql</groupId> <artifactId>postgresql</artifactId> <version>${postgresql.version}</version> </dependency> <dependency> <groupId>com.microsoft</groupId> <artifactId>sqljdbc4</artifactId> <version>${sqlserver.driver.version}</version> </dependency> <dependency> <groupId>commons-dbcp</groupId> <artifactId>commons-dbcp</artifactId> <version>${commons-dbcp.version}</version> </dependency> <dependency> <groupId>com.alibaba.druid</groupId> <artifactId>druid-wrapper</artifactId> <version>${druid-wrapper.version}</version> </dependency> <dependency> <groupId>com.alibaba</groupId> <artifactId>druid</artifactId> <version>${druid.version}</version> </dependency> <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> <dependency> <groupId>tk.mybatis</groupId> <artifactId>mapper</artifactId> <version>${mapper.version}</version> </dependency> <dependency> <groupId>javax.persistence</groupId> <artifactId>persistence-api</artifactId> <version>${persistence-api.version}</version> </dependency> <!--分页插件 --> <dependency> <groupId>com.github.pagehelper</groupId> <artifactId>pagehelper</artifactId> <version>${pagehelper.version}</version> </dependency> <dependency> <groupId>com.oracle</groupId> <artifactId>jdbc6</artifactId> <version>${oracle.version}</version> </dependency> <dependency> <groupId>junit</groupId> <artifactId>junit</artifactId> <version>${junit.version}</version> <scope>test</scope> </dependency> <!-- 日志 --> <dependency> <groupId>org.slf4j</groupId> <artifactId>slf4j-api</artifactId> <version>${slf4j.version}</version> </dependency> <dependency> <groupId>org.slf4j</groupId> <artifactId>log4j-over-slf4j</artifactId> <version>${slf4j.version}</version> </dependency> <dependency> <groupId>ch.qos.logback</groupId> <artifactId>logback-classic</artifactId> <version>${logback.version}</version> </dependency> <dependency> <groupId>commons-logging</groupId> <artifactId>commons-logging</artifactId> <version>${commons-logging.version}</version> </dependency> <!-- jackson --> <dependency> <groupId>org.codehaus.jackson</groupId> <artifactId>jackson-jaxrs</artifactId> <version>${jackson.version}</version> </dependency> <dependency> <groupId>com.fasterxml.jackson.jaxrs</groupId> <artifactId>jackson-jaxrs-json-provider</artifactId> <version>${jackson_fast.version}</version> </dependency> <!-- fastjson --> <dependency> <groupId>com.alibaba</groupId> <artifactId>fastjson</artifactId> <version>${fastjson.version}</version> </dependency> <!-- json2 --> <dependency> <groupId>com.fasterxml.jackson.core</groupId> <artifactId>jackson-databind</artifactId> <version>${jackson2.version}</version> </dependency> <!-- apache 工具包 --> <dependency> <groupId>commons-lang</groupId> <artifactId>commons-lang</artifactId> <version>${commons.lang.version}</version> </dependency> <dependency> <groupId>commons-collections</groupId> <artifactId>commons-collections</artifactId> <version>${commons-collections}</version> </dependency> <dependency> <groupId>commons-fileupload</groupId> <artifactId>commons-fileupload</artifactId> <version>${commons-fileupload}</version> </dependency> <dependency> <groupId>commons-beanutils</groupId> <artifactId>commons-beanutils</artifactId> <version>${commons-beanutils}</version> </dependency> <dependency> <groupId>javax.ws.rs</groupId> <artifactId>javax.ws.rs-api</artifactId> <version>${javax.ws.rs.version}</version> </dependency> <dependency> <groupId>javax.ws.rs</groupId> <artifactId>jsr311-api</artifactId> <version>${jsr311-api.version}</version> </dependency> <dependency> <groupId>asm</groupId> <artifactId>asm</artifactId> <version>${asm.version}</version> </dependency> <!-- Apache cxf --> <dependency> <groupId>org.apache.cxf</groupId> <artifactId>cxf-rt-frontend-jaxrs</artifactId> <version>${cxf.version}</version> </dependency> <dependency> <groupId>org.apache.cxf</groupId> <artifactId>cxf-rt-transports-http-jetty</artifactId> <version>${cxf.version}</version> </dependency> <dependency> <groupId>redis.clients</groupId> <artifactId>jedis</artifactId> <version>${jedis.version}</version> </dependency> <dependency> <groupId>org.apache.zookeeper</groupId> <artifactId>zookeeper</artifactId> <version>3.4.6</version> </dependency> <!-- Httpclient --> <dependency> <groupId>org.apache.httpcomponents</groupId> <artifactId>httpclient</artifactId> <version>${httpclient.version}</version> </dependency> <!-- param validate --> <dependency> <groupId>javax.validation</groupId> <artifactId>validation-api</artifactId> <version>${javax-validation.version}</version> </dependency> <dependency> <groupId>org.hibernate</groupId> <artifactId>hibernate-validator-annotation-processor</artifactId> <version>${hibernate-validator.version}</version> </dependency> <dependency> <groupId>org.hibernate</groupId> <artifactId>hibernate-validator</artifactId> <version>${hibernate-validator.version}</version> </dependency> </dependencies> </dependencyManagement> <dependencies> <dependency> <groupId>com.google.guava</groupId> <artifactId>guava</artifactId> <version>16.0.1</version> </dependency> <dependency> <groupId>junit</groupId> <artifactId>junit</artifactId> </dependency> <!-- spring --> <dependency> <groupId>org.springframework</groupId> <artifactId>spring-test</artifactId> <scope>test</scope> </dependency> <dependency> <groupId>org.springframework</groupId> <artifactId>spring-web</artifactId> </dependency> <dependency> <groupId>org.springframework</groupId> <artifactId>spring-tx</artifactId> </dependency> <dependency> <groupId>org.springframework</groupId> <artifactId>spring-jdbc</artifactId> </dependency> <dependency> <groupId>org.springframework</groupId> <artifactId>spring-context</artifactId> </dependency> <dependency> <groupId>org.springframework</groupId> <artifactId>spring-webmvc</artifactId> </dependency> <dependency> <groupId>org.springframework</groupId> <artifactId>spring-context-support</artifactId> </dependency> <dependency> <groupId>org.springframework</groupId> <artifactId>spring-core</artifactId> </dependency> <!-- Dao --> <dependency> <groupId>org.postgresql</groupId> <artifactId>postgresql</artifactId> </dependency> <dependency> <groupId>commons-dbcp</groupId> <artifactId>commons-dbcp</artifactId> </dependency> <dependency> <groupId>com.alibaba.druid</groupId> <artifactId>druid-wrapper</artifactId> </dependency> <dependency> <groupId>com.alibaba</groupId> <artifactId>druid</artifactId> </dependency> <dependency> <groupId>org.mybatis</groupId> <artifactId>mybatis</artifactId> </dependency> <dependency> <groupId>org.mybatis</groupId> <artifactId>mybatis-spring</artifactId> </dependency> <dependency> <groupId>tk.mybatis</groupId> <artifactId>mapper</artifactId> </dependency> <dependency> <groupId>javax.persistence</groupId> <artifactId>persistence-api</artifactId> </dependency> <!--分页插件 --> <dependency> <groupId>com.github.pagehelper</groupId> <artifactId>pagehelper</artifactId> </dependency> <dependency> <groupId>javax.servlet</groupId> <artifactId>javax.servlet-api</artifactId> </dependency> <dependency> <groupId>org.slf4j</groupId> <artifactId>log4j-over-slf4j</artifactId> </dependency> <dependency> <groupId>ch.qos.logback</groupId> <artifactId>logback-classic</artifactId> </dependency> <dependency> <groupId>commons-logging</groupId> <artifactId>commons-logging</artifactId> </dependency> <dependency> <groupId>commons-beanutils</groupId> <artifactId>commons-beanutils</artifactId> </dependency> <!-- fastjson --> <dependency> <groupId>com.alibaba</groupId> <artifactId>fastjson</artifactId> </dependency> <!-- aspectj --> <dependency> <groupId>org.aspectj</groupId> <artifactId>aspectjweaver</artifactId> </dependency> <dependency> <groupId>org.aspectj</groupId> <artifactId>aspectjrt</artifactId> </dependency> <!-- hibernate-validator --> <dependency> <groupId>org.hibernate</groupId> <artifactId>hibernate-validator-annotation-processor</artifactId> </dependency> <dependency> <groupId>org.hibernate</groupId> <artifactId>hibernate-validator</artifactId> </dependency> <!-- jackson --> <dependency> <groupId>org.codehaus.jackson</groupId> <artifactId>jackson-jaxrs</artifactId> </dependency> <dependency> <groupId>commons-fileupload</groupId> <artifactId>commons-fileupload</artifactId> </dependency> </dependencies> <build> <finalName>macow-web</finalName> <pluginManagement> <plugins> <!-- 编译插件 --> <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-compiler-plugin</artifactId> <version>3.0</version> <configuration> <encoding>${project.build.sourceEncoding}</encoding> <source>${java.version}</source> <target>${java.version}</target> <optimise>true</optimise> <debug>true</debug> </configuration> </plugin> <!-- Java源码插件 --> <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-source-plugin</artifactId> <version>2.2.1</version> <configuration> <encoding>${project.build.sourceEncoding}</encoding> </configuration> <executions> <execution> <id>attach-source</id> <phase>install</phase> <goals> <goal>jar-no-fork</goal> </goals> </execution> </executions> </plugin> </plugins> </pluginManagement> </build> </project>
package com.macow.home.first.entity; import java.io.Serializable; import java.util.Date; import javax.persistence.Column; import javax.persistence.GeneratedValue; import javax.persistence.Id; import javax.persistence.Table; @Table(name = "T_USER") public class User implements Serializable { private static final long serialVersionUID = 1L; @Id @GeneratedValue(generator = "UUID") private String id; @Column private String name; @Column private String password; @Column private Date createDate; public String getId() { return id; } public String getName() { return name; } public void setName(String name) { this.name = name; } public String getPassword() { return password; } public Date getCreateDate() { return createDate; } public void setCreateDate(Date createDate) { this.createDate = createDate; } public void setPassword(String password) { this.password = password; } public void setId(String id) { this.id = id; } }
CREATE TABLE public.t_user ( id varchar(40) NOT NULL, "name" varchar(80) NULL, password varchar(80) NULL, create_date timestamp NULL, CONSTRAINT "NewTable_pkey" PRIMARY KEY (id) )
package com.macow.home.first.mapper; import java.util.List; import org.springframework.stereotype.Repository; import tk.mybatis.mapper.common.Mapper; import com.macow.home.first.entity.User; @Repository("userMapper") public interface UserMapper extends Mapper<User> { public List<User> selectByName(User user); }
<?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.macow.home.first.mapper.UserMapper"> <select id="selectByName" resultType="com.macow.home.first.entity.User" parameterType="com.macow.home.first.entity.User"> select * from t_user where name=#{name} and create_Date=#{createDate}; </select> </mapper>
<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" xmlns:util="http://www.springframework.org/schema/util" xmlns:p="http://www.springframework.org/schema/p" 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/util http://www.springframework.org/schema/util/spring-util.xsd http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop.xsd"> <!-- 1, TOA-ASSET PostgreSQL 数据源 --> <bean id="dataSource" class="com.alibaba.druid.pool.DruidDataSource" destroy-method="close"> <property name="driverClassName" value="${ds.driverClassName}"/> <property name="url" value="${ds.url}" /> <property name="username" value="${ds.username}" /> <property name="password" value="${ds.password}" /> <!-- 配置初始化大小、最小、最大 --> <property name="initialSize" value="${ds.initialSize}" /> <property name="minIdle" value="${ds.minIdle}" /> <property name="maxActive" value="${ds.maxActive}" /> <!-- 配置获取连接等待超时的时间 --> <property name="maxWait" value="${ds.maxWait}" /> <!-- 配置间隔多久才进行一次检测,检测需要关闭的空闲连接,单位是毫秒 --> <property name="timeBetweenEvictionRunsMillis" value="${ds.timeBetweenEvictionRunsMillis}" /> <!-- 配置一个连接在池中最小生存的时间,单位是毫秒 --> <property name="minEvictableIdleTimeMillis" value="${ds.minEvictableIdleTimeMillis}" /> <property name="validationQuery" value="${ds.validationQuery}" /> <property name="testWhileIdle" value="${ds.testWhileIdle}" /> <property name="testOnBorrow" value="${ds.testOnBorrow}" /> <property name="testOnReturn" value="${ds.testOnReturn}" /> <property name="filters" value="${ds.filters}" /> </bean> <!-- 配置mybatis的SessionFactory --> <bean id="sqlSessionFactory" class="org.mybatis.spring.SqlSessionFactoryBean"> <property name="dataSource" ref="dataSource" /> <property name="typeAliasesPackage" value="com.macow.home.first.entity" /> <property name="plugins"> <array> <bean class="com.github.pagehelper.PageHelper"> <property name="properties"> <value> dialect=postgresql reasonable=true </value> </property> </bean> </array> </property> </bean> <!-- 自动扫描注册Mybatis mapper --> <bean class="tk.mybatis.spring.mapper.MapperScannerConfigurer"> <property name="basePackage" value="com.macow.home.first.mapper"/> <property name="sqlSessionFactoryBeanName" value="sqlSessionFactory"/> </bean> <!-- (事务管理)transaction manager, use JtaTransactionManager for global tx --> <bean id="transactionManager" class="org.springframework.jdbc.datasource.DataSourceTransactionManager"> <property name="dataSource" ref="dataSource" /> </bean> </beans>在src/test/java下的测试类
package com.macow.home.first; import java.util.List; import org.junit.Test; import org.junit.runner.RunWith; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.test.context.ContextConfiguration; import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; import com.macow.home.first.entity.User; import com.macow.home.first.mapper.UserMapper; @RunWith(SpringJUnit4ClassRunner.class) @ContextConfiguration("/spring-context.xml") public class UserMapperTest { private Logger logger=LoggerFactory.getLogger(this.getClass()); @Autowired private UserMapper userMapper; @Test public void testUserInsert() { User user=new User(); user.setName("王重阳123111"); user.setPassword("11112222"); userMapper.insert(user); logger.info("--------->testUserInsert end-------------"); } @Test public void testUserSelect() { List<User> select = userMapper.select(null); for(User user:select){ logger.info("--------->"+user.getName()+"-------------"); } logger.info("--------->testUserInsert end-------------"); } }
<?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: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.xsd http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop.xsd"> <context:property-placeholder location="classpath*:jdbc.properties" /> <import resource="spring-dao.xml" /> </beans>
#db ds.driverClassName=org.postgresql.Driver ds.url=jdbc:postgresql://localhost:5432/postgres ds.username=postgres ds.password=11111111 #ds.url=jdbc:postgresql://10.20.130.25:7440/toaasset #ds.username=assetopr #ds.password=paic1234 #durid datasource ds.initialSize=2 ds.minIdle=5 ds.maxActive=5 #ds.filters=stat,config ds.filters=stat ds.maxWait=60000 ds.timeBetweenEvictionRunsMillis=60000 ds.minEvictableIdleTimeMillis=300000 ds.validationQuery=SELECT 1 ds.testWhileIdle=true ds.testOnBorrow=false ds.testOnReturn=false
16:27:32.469 [main] DEBUG org.mybatis.spring.SqlSessionUtils - Creating a new SqlSession 16:27:32.469 [main] DEBUG org.mybatis.spring.SqlSessionUtils - SqlSession [org.apache.ibatis.session.defaults.DefaultSqlSession@1f82ab4] was not registered for synchronization because synchronization is not active 16:27:32.500 [main] DEBUG o.s.jdbc.datasource.DataSourceUtils - Fetching JDBC Connection from DataSource 16:27:32.640 [main] INFO c.alibaba.druid.pool.DruidDataSource - {dataSource-1} inited 16:27:32.656 [main] DEBUG o.m.s.t.SpringManagedTransaction - JDBC Connection [com.alibaba.druid.proxy.jdbc.ConnectionProxyImpl@1629e71] will not be managed by Spring 16:27:32.656 [main] DEBUG c.m.h.first.mapper.UserMapper.select - ==> Preparing: SELECT id,name,password,create_Date AS createDate FROM T_USER 16:27:32.672 [main] DEBUG c.m.h.first.mapper.UserMapper.select - ==> Parameters: 16:27:32.704 [main] DEBUG c.m.h.first.mapper.UserMapper.select - <== Total: 33 16:27:32.704 [main] DEBUG org.mybatis.spring.SqlSessionUtils - Closing non transactional SqlSession [org.apache.ibatis.session.defaults.DefaultSqlSession@1f82ab4] 16:27:32.704 [main] DEBUG o.s.jdbc.datasource.DataSourceUtils - Returning JDBC Connection to DataSource
基于springmvc mybatis junit搭建分工程,分模块的web工程框架(一)
标签:
原文地址:http://blog.csdn.net/weijiaxiaobao/article/details/51241994