1       整合ssh框架

1.1     依赖传递

只添加了一个struts2-core依赖,发现项目中出现了很多jar,

这种情况 叫 依赖传递

1.2     依赖版本冲突的解决

1、  第一声明优先原则

<dependencies>

  <!--   spring-beans-4.2.4 -->

       <dependency>

                 <groupId>org.springframework</groupId>

                 <artifactId>spring-context</artifactId>

                 <version>4.2.4.RELEASE</version>

       </dependency>

<!--   spring-beans-3.0.5 -->

       <dependency>

                 <groupId>org.apache.struts</groupId>

                 <artifactId>struts2-spring-plugin</artifactId>

                 <version>2.3.24</version>

       </dependency>

2、  路径近者优先原则

自己添加jar包

         <dependency>

                 <groupId>org.springframework</groupId>

                 <artifactId>spring-beans</artifactId>

                 <version>4.2.4.RELEASE</version>

       </dependency>

3、  排除原则

       <dependency>

                 <groupId>org.apache.struts</groupId>

                 <artifactId>struts2-spring-plugin</artifactId>

                 <version>2.3.24</version>

                 <exclusions>

                   <exclusion>

                     <groupId>org.springframework</groupId>

                     <artifactId>spring-beans</artifactId>

                   </exclusion>

                 </exclusions>

       </dependency>

4、  版本锁定原则

<properties>

                   <spring.version>4.2.4.RELEASE</spring.version>

                   <hibernate.version>5.0.7.Final</hibernate.version>

                   <struts.version>2.3.24</struts.version>

         </properties>

         <!-- 锁定版本,struts2-2.3.24、spring4.2.4、hibernate5.0.7 -->

         <dependencyManagement>

                   <dependencies>

                            <dependency>

                                     <groupId>org.springframework</groupId>

                                     <artifactId>spring-context</artifactId>

                                     <version>${spring.version}</version>

                            </dependency>

</dependencies>

</dependencyManagement>

需求:

传客户ID 页面上显示客户信息

准备数据库

1.3     构建项目

1、  创建数据库,

2、  执行准备好的sql脚本

Sql脚本的位置:

3、  完善pom.xml文件,把ssh相关的依赖都添加上去

  <!-- 属性 -->

         <properties>

                   <spring.version>4.2.4.RELEASE</spring.version>

                   <hibernate.version>5.0.7.Final</hibernate.version>

                   <struts.version>2.3.24</struts.version>

         </properties>

         <!-- 锁定版本,struts2-2.3.24、spring4.2.4、hibernate5.0.7 -->

         <dependencyManagement>

                   <dependencies>

                            <dependency>

                                     <groupId>org.springframework</groupId>

                                     <artifactId>spring-context</artifactId>

                                     <version>${spring.version}</version>

                            </dependency>

                            <dependency>

                                     <groupId>org.springframework</groupId>

                                     <artifactId>spring-aspects</artifactId>

                                     <version>${spring.version}</version>

                            </dependency>

                            <dependency>

                                     <groupId>org.springframework</groupId>

                                     <artifactId>spring-orm</artifactId>

                                     <version>${spring.version}</version>

                            </dependency>

                            <dependency>

                                     <groupId>org.springframework</groupId>

                                     <artifactId>spring-test</artifactId>

                                     <version>${spring.version}</version>

                            </dependency>

                            <dependency>

                                     <groupId>org.springframework</groupId>

                                     <artifactId>spring-web</artifactId>

                                     <version>${spring.version}</version>

                            </dependency>

                            <dependency>

                                     <groupId>org.hibernate</groupId>

                                     <artifactId>hibernate-core</artifactId>

                                     <version>${hibernate.version}</version>

                            </dependency>

                            <dependency>

                                     <groupId>org.apache.struts</groupId>

                                     <artifactId>struts2-core</artifactId>

                                     <version>${struts.version}</version>

                            </dependency>

                            <dependency>

                                     <groupId>org.apache.struts</groupId>

                                     <artifactId>struts2-spring-plugin</artifactId>

                                     <version>${struts.version}</version>

                            </dependency>

                   </dependencies>

         </dependencyManagement>

         <!-- 依赖管理 -->

         <dependencies>

                   <!-- spring -->

                   <dependency>

                            <groupId>org.springframework</groupId>

                            <artifactId>spring-context</artifactId>

                   </dependency>

                   <dependency>

                            <groupId>org.springframework</groupId>

                            <artifactId>spring-aspects</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-web</artifactId>

                   </dependency>

                   <!-- hibernate -->

                   <dependency>

                            <groupId>org.hibernate</groupId>

                            <artifactId>hibernate-core</artifactId>

                   </dependency>

                   <!-- 数据库驱动 -->

                   <dependency>

                            <groupId>mysql</groupId>

                            <artifactId>mysql-connector-java</artifactId>

                            <version>5.1.6</version>

                            <scope>runtime</scope>

                   </dependency>

                   <!-- c3p0 -->

                   <dependency>

                            <groupId>c3p0</groupId>

                            <artifactId>c3p0</artifactId>

                            <version>0.9.1.2</version>

                   </dependency>

                   <!-- 导入 struts2 -->

                   <dependency>

                            <groupId>org.apache.struts</groupId>

                            <artifactId>struts2-core</artifactId>

                   </dependency>

                   <dependency>

                            <groupId>org.apache.struts</groupId>

                            <artifactId>struts2-spring-plugin</artifactId>

                   </dependency>

                   <!-- servlet jsp -->

                   <dependency>

                            <groupId>javax.servlet</groupId>

                            <artifactId>servlet-api</artifactId>

                            <version>2.5</version>

                            <scope>provided</scope>

                   </dependency>

                   <dependency>

                            <groupId>javax.servlet</groupId>

                            <artifactId>jsp-api</artifactId>

                            <version>2.0</version>

                            <scope>provided</scope>

                   </dependency>

                   <!-- 日志 -->

                   <dependency>

                            <groupId>org.slf4j</groupId>

                            <artifactId>slf4j-log4j12</artifactId>

                            <version>1.7.2</version>

                   </dependency>

                   <!-- junit -->

                   <dependency>

                            <groupId>junit</groupId>

                            <artifactId>junit</artifactId>

                            <version>4.9</version>

                            <scope>test</scope>

                   </dependency>

                   <!-- jstl -->

                   <dependency>

                            <groupId>javax.servlet</groupId>

                            <artifactId>jstl</artifactId>

                            <version>1.2</version>

                   </dependency>

         </dependencies>

         <build>

                   <plugins>

                            <!-- 设置编译版本为1.7 -->

                            <plugin>

                                     <groupId>org.apache.maven.plugins</groupId>

                                     <artifactId>maven-compiler-plugin</artifactId>

                                     <configuration>

                                               <source>1.7</source>

                                               <target>1.7</target>

                                               <encoding>UTF-8</encoding>

                                     </configuration>

                            </plugin>

                            <!-- maven内置 的tomcat6插件 -->

                            <plugin>

                                     <groupId>org.codehaus.mojo</groupId>

                                     <artifactId>tomcat-maven-plugin</artifactId>

                                     <version>1.1</version>

                                     <configuration>

                                               <!-- 可以灵活配置工程路径 -->

                                               <path>/ssh</path>

                                               <!-- 可以灵活配置端口号 -->

                                               <port>8080</port>

                                     </configuration>

                            </plugin>

                   </plugins>

         </build>

4、  完成实体类代码

5、  完成dao代码

接口

package cn.itcast.dao;

import cn.itcast.entity.Customer;

public interface CustomerDao {

         public Customer getById(Long id);

}

实现类

package com.itcast.dao.impl;

import org.springframework.orm.hibernate5.support.HibernateDaoSupport;

import cn.itcast.dao.CustomerDao;

import cn.itcast.entity.Customer;

public class CustomerDaoImpl extends HibernateDaoSupport implements CustomerDao {

         @Override

         public Customer getById(Long id) {

                   return this.getHibernateTemplate().get(Customer.class, id);

         }

}

6、  完成service代码

接口

package com.itcast.service;

import cn.itcast.entity.Customer;

public interface CustomerService {

         public Customer getById(Long id);

}

实现类

package com.itcast.service.impl;

import com.itcast.service.CustomerService;

import cn.itcast.dao.CustomerDao;

import cn.itcast.entity.Customer;

public class CustomerServiceImpl implements CustomerService {

         private CustomerDao  customerDao;

         public void setCustomerDao(CustomerDao customerDao) {

                   this.customerDao = customerDao;

         }

         @Override

         public Customer getById(Long id) {

                   return customerDao.getById(id);

         }

}

7、  完成action代码

package cn.itcast.action;

import com.itcast.service.CustomerService;

import com.opensymphony.xwork2.ActionSupport;

import cn.itcast.entity.Customer;

public class CutomerAction extends ActionSupport {

         //两个成员变量

         private Customer  customer;

         private Long custId;

         public Customer getCustomer() {

                   return customer;

         }

         public void setCustomer(Customer customer) {

                   this.customer = customer;

         }

         private CustomerService customerService;

         public void setCustomerService(CustomerService customerService) {

                   this.customerService = customerService;

         }

         public Long getCustId() {

                   return custId;

         }

         public void setCustId(Long custId) {

                   this.custId = custId;

         }

         public String findById(){

                   customer = customerService.getById(custId);

                   return SUCCESS;

         }

}

8、  拷贝配置文件并修改

从如下图位置拿到配置文件

放入到 src/main/resources目录中

修改内容 略

9、  修改web.xml 添加spring的监听

<listener>

 <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>

</listener>

<context-param>

<param-name>contextConfigLocation</param-name>

<param-value>classpath:applicationContext.xml</param-value>

</context-param>   

10、              运行项目

2       分模块开发

依赖范围对依赖传递造成的影响

父工程来管理   聚合

2.1     创建父工程:

1、

2、创建出的父工程如下

3、在pom.Xml中添加以下信息:

 <!-- 属性 -->

         <properties>

                   <spring.version>4.2.4.RELEASE</spring.version>

                   <hibernate.version>5.0.7.Final</hibernate.version>

                   <struts.version>2.3.24</struts.version>

         </properties>

         <!-- 锁定版本,struts2-2.3.24、spring4.2.4、hibernate5.0.7 -->

         <dependencyManagement>

                   <dependencies>

                            <dependency>

                                     <groupId>org.springframework</groupId>

                                     <artifactId>spring-context</artifactId>

                                     <version>${spring.version}</version>

                            </dependency>

                            <dependency>

                                     <groupId>org.springframework</groupId>

                                     <artifactId>spring-aspects</artifactId>

                                     <version>${spring.version}</version>

                            </dependency>

                            <dependency>

                                     <groupId>org.springframework</groupId>

                                     <artifactId>spring-orm</artifactId>

                                     <version>${spring.version}</version>

                            </dependency>

                            <dependency>

                                     <groupId>org.springframework</groupId>

                                     <artifactId>spring-test</artifactId>

                                     <version>${spring.version}</version>

                            </dependency>

                            <dependency>

                                     <groupId>org.springframework</groupId>

                                     <artifactId>spring-web</artifactId>

                                     <version>${spring.version}</version>

                            </dependency>

                            <dependency>

                                     <groupId>org.hibernate</groupId>

                                     <artifactId>hibernate-core</artifactId>

                                     <version>${hibernate.version}</version>

                            </dependency>

                            <dependency>

                                     <groupId>org.apache.struts</groupId>

                                     <artifactId>struts2-core</artifactId>

                                     <version>${struts.version}</version>

                            </dependency>

                            <dependency>

                                     <groupId>org.apache.struts</groupId>

                                     <artifactId>struts2-spring-plugin</artifactId>

                                     <version>${struts.version}</version>

                            </dependency>

                   </dependencies>

         </dependencyManagement>

         <!-- 依赖管理 -->

         <dependencies>

                   <!-- spring -->

                   <dependency>

                            <groupId>org.springframework</groupId>

                            <artifactId>spring-context</artifactId>

                   </dependency>

                   <dependency>

                            <groupId>org.springframework</groupId>

                            <artifactId>spring-aspects</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-web</artifactId>

                   </dependency>

                   <!-- hibernate -->

                   <dependency>

                            <groupId>org.hibernate</groupId>

                            <artifactId>hibernate-core</artifactId>

                   </dependency>

                   <!-- 数据库驱动 -->

                   <dependency>

                            <groupId>mysql</groupId>

                            <artifactId>mysql-connector-java</artifactId>

                            <version>5.1.6</version>

                            <scope>runtime</scope>

                   </dependency>

                   <!-- c3p0 -->

                   <dependency>

                            <groupId>c3p0</groupId>

                            <artifactId>c3p0</artifactId>

                            <version>0.9.1.2</version>

                   </dependency>

                   <!-- 导入 struts2 -->

                   <dependency>

                            <groupId>org.apache.struts</groupId>

                            <artifactId>struts2-core</artifactId>

                   </dependency>

                   <dependency>

                            <groupId>org.apache.struts</groupId>

                            <artifactId>struts2-spring-plugin</artifactId>

                   </dependency>

                   <!-- servlet jsp -->

                   <dependency>

                            <groupId>javax.servlet</groupId>

                            <artifactId>servlet-api</artifactId>

                            <version>2.5</version>

                            <scope>provided</scope>

                   </dependency>

                   <dependency>

                            <groupId>javax.servlet</groupId>

                            <artifactId>jsp-api</artifactId>

                            <version>2.0</version>

                            <scope>provided</scope>

                   </dependency>

                   <!-- 日志 -->

                   <dependency>

                            <groupId>org.slf4j</groupId>

                            <artifactId>slf4j-log4j12</artifactId>

                            <version>1.7.2</version>

                   </dependency>

                   <!-- junit -->

                   <dependency>

                            <groupId>junit</groupId>

                            <artifactId>junit</artifactId>

                            <version>4.9</version>

                            <scope>test</scope>

                   </dependency>

                   <!-- jstl -->

                   <dependency>

                            <groupId>javax.servlet</groupId>

                            <artifactId>jstl</artifactId>

                            <version>1.2</version>

                   </dependency>

         </dependencies>

         <build>

                   <plugins>

                            <!-- 设置编译版本为1.7 -->

                            <plugin>

                                     <groupId>org.apache.maven.plugins</groupId>

                                     <artifactId>maven-compiler-plugin</artifactId>

                                     <configuration>

                                               <source>1.7</source>

                                               <target>1.7</target>

                                               <encoding>UTF-8</encoding>

                                     </configuration>

                            </plugin>

                            <!-- maven内置 的tomcat6插件 -->

                            <plugin>

                                     <groupId>org.codehaus.mojo</groupId>

                                     <artifactId>tomcat-maven-plugin</artifactId>

                                     <version>1.1</version>

                                     <configuration>

                                               <!-- 可以灵活配置工程路径 -->

                                               <path>/ssh</path>

                                               <!-- 可以灵活配置端口号 -->

                                               <port>8080</port>

                                     </configuration>

                            </plugin>

                   </plugins>

         </build>

4、发布到本地仓库

dao  service  web

2.2     创建dao子模块

1、在ssh-parent项目上右击 ,创建时选择 Maven Module

2、填写子模块名称ssh-dao

3、把属于dao的代码拷贝到 该模块中:

4、完成后发布到本地仓库中

2.3     创建service子模块

1、创建方式如上:

2、把属于service的代码拷贝到该工程中

3、发布到本地仓库中

2.4     创建Action子模块

1、选择war的打包方式

2、  拷贝属于action的代码和配置文件

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*:applicationContext-*.xml</param-value>

</context-param>

4、添加页面:

java使用maven项目(二)分模块开发的更多相关文章

  1. mean项目的分模块开发

    全文字版: 新建maven工程在,作为父工程用于最后集合使用,该工程不需要src,只需要一个pom.xml文件,规定一下依赖版本之类的,再建一个工具类的工程,不需要放配置文件,和工程中方法接口有关的不 ...

  2. ssm集成(maven)& 分模块开发--详细教程

    1 maven版本的ssm 1.1 最简单的版本步骤: (1) 创建maven web项目 (2) 在pom.xml中导入依赖的jar包 (3) 再写配置文件: web.xml <!DOCTYP ...

  3. Maven02——回顾、整合ssh框架、分模块开发、私服

    1 回顾 1.1 Maven的好处 节省空间 对jar包做了统一管理 依赖管理 一键构建 可跨平台 应用在大型项目可提高开发效率 1.2 Maven安装部署配置 1.3 Maven的仓库 本地仓库 远 ...

  4. spring+springmvc+hibernate架构、maven分模块开发样例小项目案例

    maven分模块开发样例小项目案例 spring+springmvc+hibernate架构 以用户管理做測试,分dao,sevices,web层,分模块开发測试!因时间关系.仅仅測查询成功.其它的准 ...

  5. java的maven项目(一)

    Maven项目管理工具 Svn + eclipse  约等于  maven量级 1       Maven的简介 1.1     什么是maven 是apache下的一个开源项目,是纯java开发,并 ...

  6. Spring_day04--HibernateTemplate介绍_整合其他方式_Spring分模块开发

    HibernateTemplate介绍 1 HibernateTemplate对hibernate框架进行封装, 直接调用HibernateTemplate里面的方法实现功能 2 HibernateT ...

  7. Struts2分模块开发

    -------------------siwuxie095 Struts2 分模块开发 在实际开发中,如果一个项目是团队开发的,也就是很多人开发的, 每个人都需要去修改 struts.xml,因为 s ...

  8. SSH框架分模块开发

    ------------------siwuxie095 SSH 框架分模块开发 1.在 Spring 核心配置文件中配置多个内容,容易造成 配置混乱,不利于维护 「分模块开发主要针对 Spring ...

  9. Struts2_day01--Struts2的核心配置文件_常量配置_分模块开发_Action编写方式

    Struts2的核心配置文件 1 名称和位置固定的 2 在配置文件中主要三个标签 package.action.result,标签里面的属性 标签package 1 类似于代码包,区别不同的actio ...

随机推荐

  1. java script 学习

    用JavaScript输出文本 <p>我的第一个段落.</p> <script> document.write(Date()); </script> & ...

  2. java线程(5)——线程池(上)

    引入: 在之前的例子中,我们需要使用线程时就直接去创建一个线程,这样既不浪费资源又十分方便.但如果我们需要创建多个并发的线程,而且短时间执行就结束了,如果还用之前的方式,就会大大降低效率和性能了. 因 ...

  3. 一道ioccc题目

    国际C语言混乱大赛的一个题: main() {printf(&unix["\021%six\012\0"],(unix)["have"]+"f ...

  4. JS frame 跨域 传值

    1.在index.html 页面定义一个 函数用于接收 子页面的调用. <iframe id="common_iframe" class="common_conte ...

  5. [Java文件操作] 将素数输出到文件

    [要求]编写程序求出10万以内的所有素数,并将这些素数输出到一个文本文件中,每行文本只包含一个素数数据. import java.util.*; import java.io.*; public cl ...

  6. 【loj6191】「美团 CodeM 复赛」配对游戏 概率期望dp

    题目描述 n次向一个栈中加入0或1中随机1个,如果一次加入0时栈顶元素为1,则将这两个元素弹栈.问最终栈中元素个数的期望是多少. 输入 一行一个正整数 n . 输出 一行一个实数,表示期望剩下的人数, ...

  7. [洛谷P4568][JLOI2011]飞行路线

    题目大意:最短路,可以有$k$条边无费用 题解:分层图最短路,建成$k$层,层与层之间的边费用为$0$ 卡点:空间计算出错,建边写错 C++ Code: #include <cstdio> ...

  8. [HAOI2007]理想的正方形 st表 || 单调队列

    ~~~题面~~~ 题解: 因为数据范围不大,而且题目要求的是正方形,所以这道题有2种解法. 1,st表. 这种解法暴力好写好理解,但是较慢.我们设st[i][j][k]表示以(i, j)为左端点,向下 ...

  9. 导致SQL执行慢的原因

    索引对大数据的查询速度的提升是非常大的,Explain可以帮你分析SQL语句是否用到相关索引. 索引类似大学图书馆建书目索引,可以提高数据检索的效率,降低数据库的IO成本.MySQL在300万条记录左 ...

  10. hbase监控实现

    目前实现的监控概览