Spring,Struts2,MyBatis,Activiti,Maven,H2,Tomcat集成(一)——Maven,Tomcat,Spring集成
1、 创建Maven Web工程
(1) 磁盘上创建Maven工程所需要的文件夹结构如下;

(2) 在与src同级目录中创建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/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.coshaho</groupId>
<artifactId>FrameIntegration</artifactId>
<packaging>war</packaging>
<version>0.0.1-SNAPSHOT</version>
<name>FrameIntegration Maven Webapp</name>
<url>http://maven.apache.org</url> </project>
(3) Eclipse导入新建的Maven工程;

(4) 在WEB-INF目录下创建web.xml文件。
<!DOCTYPE web-app PUBLIC
"-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN"
"http://java.sun.com/dtd/web-app_2_3.dtd" > <web-app version="3.0" 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_3_0.xsd"> <display-name>Framework Integration Web Application</display-name> </web-app>
2、 集成Tomcat
(1) 在pom.xml文件中添加如下配置;
<!-- 将Web项目自动部署到tomcat服务器的相关 配置信息-->
<build>
<!-- 将WebProject项目打包成WebProject.war自动部署到tomcat服务器的webapps目录下面 -->
<finalName>FrameIntegrationWeb</finalName>
<resources>
<resource>
<directory>src/main/java</directory>
<includes>
<include>**/*.properties</include>
<include>**/*.xml</include>
</includes>
<!-- 是否替换资源中的属性-->
<filtering>false</filtering>
</resource>
<resource>
<directory>src/main/resources</directory>
</resource>
<resource>
<directory>src/main/webapp</directory>
</resource>
</resources> <plugins>
<plugin>
<groupId>org.codehaus.cargo</groupId>
<artifactId>cargo-maven2-plugin</artifactId>
<version>1.2.3</version>
<configuration>
<container>
<!-- 指明使用的tomcat服务器版本 -->
<containerId>tomcat7x</containerId>
<!--指明tomcat服务器的安装目录 -->
<home>D:/software/apache-tomcat-7.0.64</home>
</container>
<type>existing</type>
<home>D:/software/apache-tomcat-7.0.64</home>
<properties>
<!-- 监听端口配置;方便远程调试 -->
<cargo.jvmargs>
-Xdebug
-Xrunjdwp:transport=dt_socket,server=y,suspend=n,address=8989
</cargo.jvmargs>
</properties>
</configuration>
<executions>
<execution>
<id>cargo-run</id>
<phase>install</phase>
<goals>
<goal>run</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
(2) src/main/webapp目录下添加index.jsp文件;
<html>
<body>
<h2>Web is started successfully!</h2>
</body>
</html>
(3) 测试Tomcat集成效果,eclipse中Run As->Maven install,前台访问http://localhost:8080/FrameIntegrationWeb。
3、 集成spring
(1) 添加Maven依赖(先添加最小依赖包);
<!-- spring4 -->
<!-- spring-core包含spring-core,logging -->
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-core</artifactId>
<version>4.1.4.RELEASE</version>
</dependency> <!-- spring-context包含spring-context, aop, beans, expression, aopalliance -->
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-context</artifactId>
<version>4.1.4.RELEASE</version>
</dependency>
<!-- 用于单元测试 -->
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.12</version>
<scope>test</scope>
</dependency>
(2) 在src/main/resources目录下配置spring.xml文件;
<?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-3.0.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context-3.0.xsd">
<!-- 自动扫描com.coshaho.learn下面所有class文件 (自动注入) -->
<context:component-scan base-package="com.coshaho.learn"/>
</beans>
(3) web.xml文件中配置spring监听器;
<listener>
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>classpath:spring.xml</param-value>
</context-param>
(4) spring测试,写如下测试类并进行单元测试。
a. HelloWorldServiceI.java
package com.coshaho.learn.service; public interface HelloWorldServiceI
{
String sayHello();
}
b. HelloWorldServiceImpl.java
package com.coshaho.learn.service.impl;
import org.springframework.stereotype.Service;
import com.coshaho.learn.service.HelloWorldServiceI;
@Service("helloWorldServiceImpl")
public class HelloWorldServiceImpl implements HelloWorldServiceI
{
public String sayHello()
{
return "Hello world, spring!";
}
}
c. SpringTest.java
package com.coshaho.learn.service.test; import org.junit.Test;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext; import com.coshaho.learn.service.HelloWorldServiceI; public class SpringTest
{
@Test
public void helloWorldTest()
{
@SuppressWarnings("resource")
ApplicationContext context = new ClassPathXmlApplicationContext("classpath:spring.xml");
HelloWorldServiceI helloWorld = (HelloWorldServiceI)context.getBean("helloWorldServiceImpl");
System.out.println(helloWorld.sayHello());
} }
d. Eclipse Run As->Junit Test
Spring,Struts2,MyBatis,Activiti,Maven,H2,Tomcat集成(一)——Maven,Tomcat,Spring集成的更多相关文章
- 手动配置三大框架整合:Spring+Struts2+mybatis
如今主流的项目框架中,数据库持久层有可能不是hibernate,而是mybatis或者ibatis,事实上它们都是一样的,以下我来把环境搭建一下: [导入相关jar包]新建web项目projectms ...
- 整合Spring+Struts2+Mybatis加spring单元测试等
前言 自己是在CentOS7的IntelliJ IDEA里开发的,里面中文输入法有问题经常用不了,所以这里用了很多chinglish,希望不要介意: 一:pom依赖 <?xml version= ...
- 用IntelliJ IDEA 开发Spring+SpringMVC+Mybatis框架 分步搭建一:建立MAVEN Web项目
一:创建maven web项目er
- Spring+SpringMVC+MyBatis+easyUI整合进阶篇(十二)Spring集成Redis缓存
作者:13 GitHub:https://github.com/ZHENFENG13 版权声明:本文为原创文章,未经允许不得转载. 整合Redis 本来以为类似的Redis教程和整合代码应该会很多,因 ...
- spring+struts2+mybatis
struts2.2.3 + spring3.1.0 + mybatis3.1.0集成简单demo 项目下载地址:http://download.csdn.net/detail/afgasdg/4171 ...
- 整合第二次(SSM第一次)------------>spring+struts2+mybatis
今天我们来讲解一下SSM整合,感觉整合这个比上一篇整合更费时,原因在于自己不太熟悉MyBatis了,下午的时候恶补了一下,看了一下相关的文档和PDF电子书,知识真的是你不用就会忘记的,以后还是不能懈怠 ...
- Spring+Struts2+Mybatis框架搭建时的常见典型问题
搭建SSM框架时,总是遇到这样那样的问题,有的一眼就能看出来,有的需要经验的积累.现将自己搭建SSM框架时遇到的典型问题总结如下: 一.Struts2框架下的action中无法使用@Autowired ...
- 6、Spring+Struts2+MyBatis(mybatis有代理)整合增删改查
1.创建如下的oracle脚本 create table userinfo (id ), name ), password telephone ), isadmin )); --4.2 用户表序列 c ...
- 5、Spring+Struts2+MyBatis+分页(mybatis无代理)增删改查
1.创建如下项目结构 2.在src下的com.entity包下创建Dept.java package com.entity; /** * 部门表 * @author Holly老师 * */ publ ...
- Spring+Struts2+Mybatis整合
1. 创建项目 2. 添加Spring能力 使用MyEclipse自动加载Struts2和Spring的jar包和配置文件,并在web.xml文件中添加上下文和监听器 web.xml文件如下: < ...
随机推荐
- 【CF316G3】Good Substrings 后缀自动机
[CF316G3]Good Substrings 题意:给出n个限制(p,l,r),我们称一个字符串满足一个限制当且仅当这个字符串在p中的出现次数在[l,r]之间.现在想问你S的所有本质不同的子串中, ...
- 【BZOJ5091】摘苹果 概率
[BZOJ5091]摘苹果 Description 小Q的工作是采摘花园里的苹果.在花园中有n棵苹果树以及m条双向道路,苹果树编号依次为1到n,每条道路的两 端连接着两棵不同的苹果树.假设第i棵苹果树 ...
- Office2007 每次打开斗需要检查 【配置进度】
打开C:\Program Files\Common Files\microsoft shared\OFFICE12\Office Setup Controller目录下将SETUP.EXE 重命名为 ...
- 无约束优化方法(梯度法-牛顿法-BFGS- L-BFGS)
本文讲解的是无约束优化中几个常见的基于梯度的方法,主要有梯度下降与牛顿方法.BFGS 与 L-BFGS 算法. 梯度下降法是基于目标函数梯度的,算法的收敛速度是线性的,并且当问题是病态时或者问题规模较 ...
- Solve Error: 'has incomplete type', foward declaration of 'class x'
在C++的OOB编程中,有时候我们会遇到这样的错误Error: 'has incomplete type',forward declaration of 'class x',那么是什么原因引起的这个问 ...
- 【转】Ant与Ivy的安装
一.简介 Apache Ant,是一个将软件编译.测试.部署等步骤联系在一起加以自动化的一个工具,大多用于Java环境中的软件开发.更多介绍 Apache Ivy,是一个管理项目依赖的工具.更多介绍请 ...
- Oracle字符串连接的方法
Oracle数据库中,使用“||”进行字符串连接,下面就让我们一起了解一下Oracle数据库中字符串连接的方法,希望对您能有所帮助. 和其他数据库系统类似,Oracle字符串连接使用“||”进行字符串 ...
- Zookeeper简介及单机、集群模式搭建
1.zookeeper简介 一个开源的分布式的,为分布式应用提供协调服务的apache项目. 提供一个简单的原语集合,以便于分布式应用可以在它之上构建更高层次的同步服务. 设计非常易于编程,它使用的是 ...
- 自己实现一个简单的网络音乐mp3播放器
大繁至简,把思路搞清楚才是最重要的,如何去做依托于使用什么来实现这项功能 列出我使用的基本类 NSURLSessionDataTask 数据获取类 NSFileHandle 数据缓存和数据读取类 Au ...
- cocoapods卸载与安装
引用自:https://www.aliyun.com/jiaocheng/389907.html 一.首先卸载pod which pod 得到pod的路径 sudo rm -rf <pod的路径 ...