1、  创建Maven Web工程

(1)       磁盘上创建Maven工程所需要的文件夹结构如下;

(2)       在与src同级目录中创建pom.xml文件;

  1. <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  2. xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
  3. <modelVersion>4.0.0</modelVersion>
  4. <groupId>com.coshaho</groupId>
  5. <artifactId>FrameIntegration</artifactId>
  6. <packaging>war</packaging>
  7. <version>0.0.1-SNAPSHOT</version>
  8. <name>FrameIntegration Maven Webapp</name>
  9. <url>http://maven.apache.org</url>
  10.  
  11. </project>

(3)       Eclipse导入新建的Maven工程;

(4)       在WEB-INF目录下创建web.xml文件。

  1. <!DOCTYPE web-app PUBLIC
  2. "-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN"
  3. "http://java.sun.com/dtd/web-app_2_3.dtd" >
  4.  
  5. <web-app version="3.0" xmlns="http://java.sun.com/xml/ns/javaee"
  6. xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  7. xsi:schemaLocation="http://java.sun.com/xml/ns/javaee
  8. http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd">
  9.  
  10. <display-name>Framework Integration Web Application</display-name>
  11.  
  12. </web-app>

2、  集成Tomcat

(1)       在pom.xml文件中添加如下配置;

  1. <!-- 将Web项目自动部署到tomcat服务器的相关 配置信息-->
  2. <build>
  3. <!-- 将WebProject项目打包成WebProject.war自动部署到tomcat服务器的webapps目录下面 -->
  4. <finalName>FrameIntegrationWeb</finalName>
  5. <resources>
  6. <resource>
  7. <directory>src/main/java</directory>
  8. <includes>
  9. <include>**/*.properties</include>
  10. <include>**/*.xml</include>
  11. </includes>
  12. <!-- 是否替换资源中的属性-->
  13. <filtering>false</filtering>
  14. </resource>
  15. <resource>
  16. <directory>src/main/resources</directory>
  17. </resource>
  18. <resource>
  19. <directory>src/main/webapp</directory>
  20. </resource>
  21. </resources>
  22.  
  23. <plugins>
  24. <plugin>
  25. <groupId>org.codehaus.cargo</groupId>
  26. <artifactId>cargo-maven2-plugin</artifactId>
  27. <version>1.2.3</version>
  28. <configuration>
  29. <container>
  30. <!-- 指明使用的tomcat服务器版本 -->
  31. <containerId>tomcat7x</containerId>
  32. <!--指明tomcat服务器的安装目录 -->
  33. <home>D:/software/apache-tomcat-7.0.64</home>
  34. </container>
  35. <type>existing</type>
  36. <home>D:/software/apache-tomcat-7.0.64</home>
  37. <properties>
  38. <!-- 监听端口配置;方便远程调试 -->
  39. <cargo.jvmargs>
  40. -Xdebug
  41. -Xrunjdwp:transport=dt_socket,server=y,suspend=n,address=8989
  42. </cargo.jvmargs>
  43. </properties>
  44. </configuration>
  45. <executions>
  46. <execution>
  47. <id>cargo-run</id>
  48. <phase>install</phase>
  49. <goals>
  50. <goal>run</goal>
  51. </goals>
  52. </execution>
  53. </executions>
  54. </plugin>
  55. </plugins>
  56. </build>

(2)       src/main/webapp目录下添加index.jsp文件;

  1. <html>
  2. <body>
  3. <h2>Web is started successfully!</h2>
  4. </body>
  5. </html>

(3)       测试Tomcat集成效果,eclipse中Run As->Maven install,前台访问http://localhost:8080/FrameIntegrationWeb。

3、  集成spring

(1)       添加Maven依赖(先添加最小依赖包);

  1. <!-- spring4 -->
  2. <!-- spring-core包含spring-core,logging -->
  3. <dependency>
  4. <groupId>org.springframework</groupId>
  5. <artifactId>spring-core</artifactId>
  6. <version>4.1.4.RELEASE</version>
  7. </dependency>
  8.  
  9. <!-- spring-context包含spring-context, aop, beans, expression, aopalliance -->
  10. <dependency>
  11. <groupId>org.springframework</groupId>
  12. <artifactId>spring-context</artifactId>
  13. <version>4.1.4.RELEASE</version>
  14. </dependency>
  15. <!-- 用于单元测试 -->
  16. <dependency>
  17. <groupId>junit</groupId>
  18. <artifactId>junit</artifactId>
  19. <version>4.12</version>
  20. <scope>test</scope>
  21. </dependency>

(2)       在src/main/resources目录下配置spring.xml文件;

  1. <?xml version="1.0" encoding="UTF-8"?>
  2. <beans xmlns="http://www.springframework.org/schema/beans"
  3. xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  4. xmlns:context="http://www.springframework.org/schema/context"
  5. xsi:schemaLocation="http://www.springframework.org/schema/beans
  6. http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
  7. http://www.springframework.org/schema/context
  8. http://www.springframework.org/schema/context/spring-context-3.0.xsd">
  9. <!-- 自动扫描com.coshaho.learn下面所有class文件 (自动注入) -->
  10. <context:component-scan base-package="com.coshaho.learn"/>
  11. </beans>

(3)       web.xml文件中配置spring监听器;

  1. <listener>
  2. <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
  3. </listener>
  4. <context-param>
  5. <param-name>contextConfigLocation</param-name>
  6. <param-value>classpath:spring.xml</param-value>
  7. </context-param>

(4)       spring测试,写如下测试类并进行单元测试。

a. HelloWorldServiceI.java

  1. package com.coshaho.learn.service;
  2.  
  3. public interface HelloWorldServiceI
  4. {
  5. String sayHello();
  6. }

b. HelloWorldServiceImpl.java

  1. package com.coshaho.learn.service.impl;
  2.  
  3. import org.springframework.stereotype.Service;
  4.  
  5. import com.coshaho.learn.service.HelloWorldServiceI;
  6.  
  7. @Service("helloWorldServiceImpl")
  8. public class HelloWorldServiceImpl implements HelloWorldServiceI
  9. {
  10. public String sayHello()
  11. {
  12. return "Hello world, spring!";
  13. }
  14. }

c. SpringTest.java

  1. package com.coshaho.learn.service.test;
  2.  
  3. import org.junit.Test;
  4. import org.springframework.context.ApplicationContext;
  5. import org.springframework.context.support.ClassPathXmlApplicationContext;
  6.  
  7. import com.coshaho.learn.service.HelloWorldServiceI;
  8.  
  9. public class SpringTest
  10. {
  11. @Test
  12. public void helloWorldTest()
  13. {
  14. @SuppressWarnings("resource")
  15. ApplicationContext context = new ClassPathXmlApplicationContext("classpath:spring.xml");
  16. HelloWorldServiceI helloWorld = (HelloWorldServiceI)context.getBean("helloWorldServiceImpl");
  17. System.out.println(helloWorld.sayHello());
  18. }
  19.  
  20. }

d. Eclipse Run As->Junit Test

Spring,Struts2,MyBatis,Activiti,Maven,H2,Tomcat集成(一)——Maven,Tomcat,Spring集成的更多相关文章

  1. 手动配置三大框架整合:Spring+Struts2+mybatis

    如今主流的项目框架中,数据库持久层有可能不是hibernate,而是mybatis或者ibatis,事实上它们都是一样的,以下我来把环境搭建一下: [导入相关jar包]新建web项目projectms ...

  2. 整合Spring+Struts2+Mybatis加spring单元测试等

    前言 自己是在CentOS7的IntelliJ IDEA里开发的,里面中文输入法有问题经常用不了,所以这里用了很多chinglish,希望不要介意: 一:pom依赖 <?xml version= ...

  3. 用IntelliJ IDEA 开发Spring+SpringMVC+Mybatis框架 分步搭建一:建立MAVEN Web项目

    一:创建maven web项目er

  4. Spring+SpringMVC+MyBatis+easyUI整合进阶篇(十二)Spring集成Redis缓存

    作者:13 GitHub:https://github.com/ZHENFENG13 版权声明:本文为原创文章,未经允许不得转载. 整合Redis 本来以为类似的Redis教程和整合代码应该会很多,因 ...

  5. spring+struts2+mybatis

    struts2.2.3 + spring3.1.0 + mybatis3.1.0集成简单demo 项目下载地址:http://download.csdn.net/detail/afgasdg/4171 ...

  6. 整合第二次(SSM第一次)------------>spring+struts2+mybatis

    今天我们来讲解一下SSM整合,感觉整合这个比上一篇整合更费时,原因在于自己不太熟悉MyBatis了,下午的时候恶补了一下,看了一下相关的文档和PDF电子书,知识真的是你不用就会忘记的,以后还是不能懈怠 ...

  7. Spring+Struts2+Mybatis框架搭建时的常见典型问题

    搭建SSM框架时,总是遇到这样那样的问题,有的一眼就能看出来,有的需要经验的积累.现将自己搭建SSM框架时遇到的典型问题总结如下: 一.Struts2框架下的action中无法使用@Autowired ...

  8. 6、Spring+Struts2+MyBatis(mybatis有代理)整合增删改查

    1.创建如下的oracle脚本 create table userinfo (id ), name ), password telephone ), isadmin )); --4.2 用户表序列 c ...

  9. 5、Spring+Struts2+MyBatis+分页(mybatis无代理)增删改查

    1.创建如下项目结构 2.在src下的com.entity包下创建Dept.java package com.entity; /** * 部门表 * @author Holly老师 * */ publ ...

  10. Spring+Struts2+Mybatis整合

    1. 创建项目 2. 添加Spring能力 使用MyEclipse自动加载Struts2和Spring的jar包和配置文件,并在web.xml文件中添加上下文和监听器 web.xml文件如下: < ...

随机推荐

  1. spring配置多视图解析器

    最近做一个小项目(移动端),自己搭了个简单的SSM框架(spring + spring MVC + Mybitis),展示层本来选用的是jsp,各方便都已经搭建好,结果发现有些页面需要用到H5的一些功 ...

  2. sublime设置tab键为4个空格

    在使用sublime的时候,有时候新建的文件,默认的缩进是2个,那么如何将sublime设置tab键为4个空格呢? 具体方法: 配置: , "translate_tabs_to_spaces ...

  3. nginx 开机自动启动

    接下来聊一聊nginx的开机自启吧 看了看都是用脚本启动的,我也就不扯啥犊子了,都是前人经验 我的操作系统是centos 7 nginx版本是1.10.3 首先看一下自己的nginx配置 我的是 ./ ...

  4. C3P0连接池配置(C3P0Utils.java)

    配置文件 c3p0-config.xml <?xml version="1.0" encoding="UTF-8"?> <c3p0-confi ...

  5. matlab中norm函数的用法

    格式:n=norm(A,p) 功能:norm函数可计算几种不同类型的矩阵范数,根据p的不同可得到不同的范数 以下是Matlab中help norm 的解释 NORM   Matrix or vecto ...

  6. kdevelop使用笔记

    https://www.cnblogs.com/-Mr-y/p/7707176.html#_label7

  7. dockerfile学习笔记

    Dockfile 参考资料:http://www.cnblogs.com/CloudMan6/p/6864000.html http://www.cnblogs.com/CloudMan6/p/687 ...

  8. 新购买的vps应该做的几件事情

    1. 修改root密码      passwd   root 2.新建用户     useradd  vinentguo 3.配置免密码登陆 .使用新建用户登陆vps. mkdir ~/.ssh/ch ...

  9. Spark 数据源

    一.mysql作为数据源 import org.apache.spark.sql.{DataFrame, Dataset, Row, SparkSession} /** * mysql作为数据源 * ...

  10. http_build_query

    http_build_query (PHP 5) http_build_query -- 生成 url-encoded 之后的请求字符串描述string http_build_query ( arra ...