Maven项目的拆分与聚合

时间:2021-04-18 07:40:58

---------------------siwuxie095

 
 

 
 

 
 

 
 

 
 

 
 

 
 

 
 

 
 

Maven 项目的拆分与聚合

 
 

 
 

1、对已有的
Maven 项目 maven-ssh 先拆分,再聚合

 
 

(1)拆分思路:将
DAO 层、Service 层、Web 层

的代码以及配置文件分别提取到三个表现上独立的项

目中(实际上并不独立)

 
 

(2)聚合思路:对拆分后的项目进行聚合

 
 

 
 

 
 

 
 

2、对应到
Maven 中,就是父项目与子模块的概念

 
 

(1)父项目将子模块聚合在一起

 
 

(2)子模块继承父项目中的依赖

 
 

 
 

 
 

 
 

3、具体如下:

 
 

(1)ssh-parent(父项目)

 
 

(2)ssh-dao(子模块)

 
 

(3)ssh-service(子模块)

 
 

(4)ssh-web(子模块)

 
 

 
 

 
 

 
 

4、父项目和子模块的创建方法

 
 

(1)父项目:File->New->Maven Project

 
 

(2)子模块:选择父项目,右键->New->Other->Maven->Maven Module

 
 

「先有父项目,再有子模块」

 
 

注意:创建时要勾选
跳过原型选项

跳过骨架选项

 
 

Maven项目的拆分与聚合

 
 

 
 

 
 

 
 

5、创建父项目
ssh-parent

 
 

Maven项目的拆分与聚合

 
 

 
 

注意:打包方式(Packaging)要选择 pom

 
 

 
 

 
 

 
 

6、父项目
ssh-parent 目录结构一览:

 
 

Maven项目的拆分与聚合

 
 

 
 

当前父项目的核心配置文件

 
 

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.siwuxie095.ssh</groupId>

<artifactId>ssh-parent</artifactId>

<version>0.0.1-SNAPSHOT</version>

<packaging>pom</packaging>

 

<!--

modules 标签用于配置子模块,其中的

内容无需手动配置,随着子模块的创建,

将自动生成

 

当然,也可以手动配置

-->

<modules>

<module>ssh-dao</module>

<module>ssh-service</module>

<module>ssh-web</module>

</modules>

 

 

<!-- 归类依赖 -->

<properties>

<struts.version>2.3.33</struts.version>

<spring.version>4.3.7.RELEASE</spring.version>

<hibernate.version>5.0.12.Final</hibernate.version>

</properties>

 

 

<dependencies>

 

<!-- +++++++ (1) Struts2 相关 +++++++ -->

 

<!-- Struts2 相关的基本依赖 -->

<dependency>

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

<artifactId>struts2-core</artifactId>

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

<!--

由于 Struts2 和 Hibernate 中都有 javassist,

为避免冲突,留下高版本,排除低版本即可

 

这里,Struts2 中的 javassist 版本更低

-->

<exclusions>

<exclusion>

<groupId>javassist</groupId>

<artifactId>javassist</artifactId>

</exclusion>

</exclusions>

</dependency>

 

 

<!-- +++++++ (2) Spring 相关 +++++++ -->

 

<!-- Spring 相关的基本依赖 -->

<dependency>

<groupId>org.springframework</groupId>

<artifactId>spring-context</artifactId>

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

</dependency>

 

<!-- Spring AOP 相关的依赖 -->

<dependency>

<groupId>org.springframework</groupId>

<artifactId>spring-aspects</artifactId>

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

</dependency>

 

<!-- Spring 单元测试相关的依赖 -->

<dependency>

<groupId>org.springframework</groupId>

<artifactId>spring-test</artifactId>

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

</dependency>

 

 

<!-- +++++++ (3) Hibernate 相关 +++++++ -->

 

<!-- Hibernate 相关的基本依赖 -->

<dependency>

<groupId>org.hibernate</groupId>

<artifactId>hibernate-core</artifactId>

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

</dependency>

 

 

<!-- +++++++ (4) SSH 整合相关 +++++++ -->

 

<!-- Struts2 整合 Spring 相关的依赖 -->

<dependency>

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

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

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

</dependency>

 

<!-- Spring 整合 Web 项目相关的依赖 -->

<dependency>

<groupId>org.springframework</groupId>

<artifactId>spring-web</artifactId>

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

</dependency>

 

<!-- Spring 整合 Hibernate 相关的依赖 -->

<dependency>

<groupId>org.springframework</groupId>

<artifactId>spring-orm</artifactId>

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

</dependency>

 

 

<!-- +++++++ (5) 数据库连接相关 +++++++ -->

 

<!-- JDBC 驱动相关的依赖 -->

<dependency>

<groupId>mysql</groupId>

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

<version>5.1.43</version>

<scope>runtime</scope>

</dependency>

 

<!-- C3P0 连接池相关的依赖 -->

<dependency>

<groupId>c3p0</groupId>

<artifactId>c3p0</artifactId>

<version>0.9.1.2</version>

</dependency>

 

 

<!-- +++++++ (6) 日志相关 +++++++ -->

 

<!-- 日志相关的依赖 -->

<dependency>

<groupId>org.slf4j</groupId>

<artifactId>slf4j-log4j12</artifactId>

<version>1.7.25</version>

</dependency>

 

 

<!-- +++++++ (7) 其它相关 +++++++ -->

 

<!-- JUnit 相关的依赖 -->

<dependency>

<groupId>junit</groupId>

<artifactId>junit</artifactId>

<version>4.12</version>

<scope>test</scope>

</dependency>

 

<!-- JSTL 相关的依赖 -->

<dependency>

<groupId>javax.servlet</groupId>

<artifactId>jstl</artifactId>

<version>1.2</version>

</dependency>

 

<!-- servlet-api 相关的依赖 -->

<dependency>

<groupId>javax.servlet</groupId>

<artifactId>servlet-api</artifactId>

<version>2.5</version>

<scope>provided</scope>

</dependency>

 

<!-- jsp-api 相关的依赖 -->

<dependency>

<groupId>javax.servlet</groupId>

<artifactId>jsp-api</artifactId>

<version>2.0</version>

<scope>provided</scope>

</dependency>

 

</dependencies>

 

 

</project>

 
 

 
 

父项目中并不进行编码,它的主要作用是:

 
 

(1)在
pom.xml 中声明依赖,子模块继承之

 
 

(2)在
pom.xml 中将各个子模块聚合到一起

 
 

 
 

 
 

 
 

7、创建子模块
ssh-dao

 
 

Maven项目的拆分与聚合

 
 

Maven项目的拆分与聚合

 
 

 
 

注意:打包方式(Packaging)要选择 jar

 
 

 
 

 
 

 
 

 

8、子模块
ssh-dao 目录结构一览:

 
 

Maven项目的拆分与聚合

 
 

 
 

(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>

 

<parent>

<groupId>com.siwuxie095.ssh</groupId>

<artifactId>ssh-parent</artifactId>

<version>0.0.1-SNAPSHOT</version>

</parent>

 

<artifactId>ssh-dao</artifactId>

 

</project>

 
 

 
 

 
 

(2)实体类及其
Hibernate 映射配置文件

 
 

User.java:

 
 

package com.siwuxie095.entity;

 
 

public class User {

 

Integer uid;

String username;

String address;

 

public Integer getUid() {

return uid;

}

public
void setUid(Integer uid) {

this.uid = uid;

}

 

public String getUsername() {

return username;

}

public
void setUsername(String username) {

this.username = username;

}

 

public String getAddress() {

return address;

}

public
void setAddress(String address) {

this.address = address;

}

 

@Override

public String toString() {

return
"User [uid=" + uid + ", username=" + username +

", address=" + address + "]";

}

 

}

 
 

 
 

 
 

User.hbm.xml:

 
 

<?xml
version="1.0"
encoding="UTF-8"?>

<!DOCTYPE hibernate-mapping PUBLIC

"-//Hibernate/Hibernate Mapping DTD 3.0//EN"

"http://www.hibernate.org/dtd/hibernate-mapping-3.0.dtd">

 

<hibernate-mapping>

 
 

<class
name="com.siwuxie095.entity.User"
table="t_user">

 

<id
name="uid"
column="uid">

<generator
class="native"></generator>

</id>

 

<property
name="username"
column="username"></property>

<property
name="address"
column="address"></property>

 

</class>

 

</hibernate-mapping>

 
 

 
 

 
 

(3)Hibernate 核心配置文件

 
 

hibernate.cfg.xml:

 
 

<?xml
version="1.0"
encoding="UTF-8"?>

<!DOCTYPE hibernate-configuration PUBLIC

"-//Hibernate/Hibernate Configuration DTD 3.0//EN"

"http://www.hibernate.org/dtd/hibernate-configuration-3.0.dtd">

<hibernate-configuration>

<session-factory>

 

 

<property
name="hibernate.show_sql">true</property>

<property
name="hibernate.format_sql">true</property>

<!-- 注意:只有配置 hibernate.hbm2ddl.auto 为 update,才能自动创建表 -->

<property
name="hibernate.hbm2ddl.auto">update</property>

<property
name="hibernate.dialect">org.hibernate.dialect.MySQLDialect</property>

<!--

原来的配置:

<property name="hibernate.current_session_context_class">thread</property>

 

在 SSH 框架整合中会报错,要么将这个配置删了,要么改成如下配置

 

参考链接:http://blog.csdn.net/maoyuanming0806/article/details/61417995

-->

<property
name="hibernate.current_session_context_class">

org.springframework.orm.hibernate5.SpringSessionContext

</property>

<!--

如果没有如下配置,控制台将有如下异常信息:

Disabling contextual LOB creation as createClob() method threw error :

java.lang.reflect.InvocationTargetException

 

* 配置 *

<property name="hibernate.temp.use_jdbc_metadata_defaults">false</property>

 

其实该配置加不加都无所谓,并不影响什么

 

参考链接:http://blog.csdn.net/jiong_long/article/details/51340685

-->

<property
name="hibernate.temp.use_jdbc_metadata_defaults">false</property>

 

 

<mapping
resource="com/siwuxie095/entity/User.hbm.xml"/>

 

 

</session-factory>

</hibernate-configuration>

 
 

 
 

 
 

(4)DAO 接口及其实现类

 
 

UserDao.java:

 
 

package com.siwuxie095.dao;

 
 

import com.siwuxie095.entity.User;

 
 

public interface UserDao {

 
 

void add(User user);

 

}

 
 

 
 

 
 

UserDaoImpl.java:

 
 

package com.siwuxie095.dao.impl;

 
 

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

 
 

import com.siwuxie095.dao.UserDao;

import com.siwuxie095.entity.User;

 
 

/**

* 让 DAO 接口实现类继承 HibernateDaoSupport 类,直接获取 HibernateTemplate

*/

public class UserDaoImpl extends HibernateDaoSupport implements UserDao {

 

@Override

public
void add(User user) {

 

// 直接通过 this 获取 HibernateTemplate,调用 save() 方法保存

this.getHibernateTemplate().save(user);

 

/*

* 此时,也可以获取 SessionFactory

*

* 法一:this.getSessionFactory()

* 法二:this.getHibernateTemplate().getSessionFactory()

*

*

* 此时,也可以获取 Session

*

* 法一:this.getSessionFactory().getCurrentSession()

* 法二:...

*/

}

 

}

 
 

 
 

 
 

(5)拆分后的
Spring 核心配置文件

 
 

applicationContext-dao.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:aop="http://www.springframework.org/schema/aop"

xmlns:context="http://www.springframework.org/schema/context"

xmlns:tx="http://www.springframework.org/schema/tx"

xsi:schemaLocation="

http://www.springframework.org/schema/beans

http://www.springframework.org/schema/beans/spring-beans.xsd

http://www.springframework.org/schema/aop

http://www.springframework.org/schema/aop/spring-aop.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">

 

 

<!-- (1) -->

<!-- 配置 C3P0 连接池 -->

<bean
id="dataSource"
class="com.mchange.v2.c3p0.ComboPooledDataSource">

<property
name="driverClass"
value="com.mysql.jdbc.Driver"/>

<!--

jdbc:mysql:///ssh_db 是 jdbc:mysql://localhost:3306/ssh_db 的简写

-->

<property
name="jdbcUrl"
value="jdbc:mysql:///ssh_db"/>

<property
name="user"
value="root"/>

<property
name="password"
value="8888"/>

</bean>

 

 

<!-- SessionFactory 对象的创建交给 Spring 进行管理 -->

<bean
id="sessionFactory"

class="org.springframework.orm.hibernate5.LocalSessionFactoryBean">

<!--

因为在 Hibernate 核心配置文件中,没有数据库配置,

而是在 Spring 的核心配置文件中进行配置,所以需要

注入 dataSource

LocalSessionFactoryBean 中有相关属性,所以可以

注入

-->

<property
name="dataSource"
ref="dataSource"></property>

<!-- 指定 Hibernate 核心配置文件的位置 -->

<property
name="configLocations"
value="classpath:hibernate.cfg.xml"></property>

</bean>

 

 

 

<!-- (2) -->

<!-- 配置事务管理器 HibernateTransactionManager -->

<bean
id="transactionManager"

class="org.springframework.orm.hibernate5.HibernateTransactionManager">

<!--注入 SessionFactory 对象 -->

<property
name="sessionFactory"
ref="sessionFactory"></property>

</bean>

 

<!-- 开启事务注解 -->

<tx:annotation-driven
transaction-manager="transactionManager"/>

 

 

 

<!-- (3) -->

<!-- 配置 Dao 实现类对象 -->

<bean
id="userDaoImpl"
class="com.siwuxie095.dao.impl.UserDaoImpl">

<!-- 注入 SessionFactory 对象 -->

<property
name="sessionFactory"
ref="sessionFactory"></property>

</bean>

 

 

</beans>

 
 

 
 

 
 

 
 

9、创建子模块
ssh-service

 
 

Maven项目的拆分与聚合

 
 

Maven项目的拆分与聚合

 
 

 
 

注意:打包方式(Packaging)要选择 jar

 
 

 
 

 
 

 
 

10、子模块
ssh-service 目录结构一览:

 
 

Maven项目的拆分与聚合

 
 

 
 

(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>

 

<parent>

<groupId>com.siwuxie095.ssh</groupId>

<artifactId>ssh-parent</artifactId>

<version>0.0.1-SNAPSHOT</version>

</parent>

 

<artifactId>ssh-service</artifactId>

 

<!--

ssh-service 依赖于 ssh-dao,所以添加 ssh-dao 依赖

 

注意:由于添加了 ssh-dao 依赖,在对 ssh-service

执行 compile、test、install 等命令之前,必须先将

ssh-parent 安装(install)到本地仓库,否则这些命令

将执行失败

-->

<dependencies>

<dependency>

<groupId>com.siwuxie095.ssh</groupId>

<artifactId>ssh-dao</artifactId>

<version>0.0.1-SNAPSHOT</version>

</dependency>

</dependencies>

 

</project>

 
 

 
 

 
 

(2)Service 类

 
 

UserService.java:

 
 

package com.siwuxie095.service;

 
 

import org.springframework.transaction.annotation.Transactional;

 
 

import com.siwuxie095.dao.UserDao;

import com.siwuxie095.entity.User;

 
 

@Transactional

public class UserService {

 

private UserDao userDao;

 

public
void setUserDao(UserDao userDao) {

this.userDao = userDao;

}

 
 

public
void add(User user) {

userDao.add(user);

}

 

}

 
 

 
 

 
 

(3)拆分后的
Spring 核心配置文件

 
 

applicationContext-service.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:aop="http://www.springframework.org/schema/aop"

xmlns:context="http://www.springframework.org/schema/context"

xmlns:tx="http://www.springframework.org/schema/tx"

xsi:schemaLocation="

http://www.springframework.org/schema/beans

http://www.springframework.org/schema/beans/spring-beans.xsd

http://www.springframework.org/schema/aop

http://www.springframework.org/schema/aop/spring-aop.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">

 

 

<!-- 配置 Service 对象 -->

<bean
id="userService"
class="com.siwuxie095.service.UserService">

<property
name="userDao"
ref="userDaoImpl"></property>

</bean>

 

 

</beans>

 
 

 
 

 
 

 
 

11、创建子模块
ssh-web

 
 

Maven项目的拆分与聚合

 
 

Maven项目的拆分与聚合

 
 

 
 

注意:打包方式(Packaging)要选择 war

 
 

 
 

 
 

 
 

12、子模块
ssh-web 目录结构一览:

 
 

Maven项目的拆分与聚合

 
 

 
 

(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>

 

<parent>

<groupId>com.siwuxie095.ssh</groupId>

<artifactId>ssh-parent</artifactId>

<version>0.0.1-SNAPSHOT</version>

</parent>

 

<artifactId>ssh-web</artifactId>

<packaging>war</packaging>

 

<!--

ssh-web 依赖于 ssh-service,所以添加 ssh-service 依赖

 

注意:由于添加了 ssh-service 依赖,在对 ssh-web

执行 compile、test、install 等命令之前,必须先将

ssh-parent 安装(install)到本地仓库,否则这些命令

将执行失败

-->

<dependencies>

<dependency>

<groupId>com.siwuxie095.ssh</groupId>

<artifactId>ssh-service</artifactId>

<version>0.0.1-SNAPSHOT</version>

</dependency>

</dependencies>

 

</project>

 
 

 
 

 
 

(2)JSP 页面

 
 

add.jsp:

 
 

<%@ page language="java" contentType="text/html; charset=UTF-8"

pageEncoding="UTF-8"%>

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">

<html>

<head>

<meta
http-equiv="Content-Type"
content="text/html; charset=UTF-8">

<title>添加用户</title>

</head>

<body>

 

<form
action="${pageContext.request.contextPath }/user_add.action"
method="post">

用户名:<input
type="text"
name="username"
/>

地址:<input
type="text"
name="address"
/>

<input
type="submit"
name="提交"
/>

</form>

 

</body>

</html>

 
 

 
 

 
 

succ.jsp:

 
 

<%@ page language="java" contentType="text/html; charset=UTF-8"

pageEncoding="UTF-8"%>

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">

<html>

<head>

<meta
http-equiv="Content-Type"
content="text/html; charset=UTF-8">

<title>添加成功</title>

</head>

<body>

 

<h1>添加成功!<a
href="${pageContext.request.contextPath }/add.jsp">继续添加</a></h1>

 

</body>

</html>

 
 

 
 

 
 

(3)Action 类

 
 

UserAction.java:

 
 

package com.siwuxie095.action;

 
 

import com.opensymphony.xwork2.ActionSupport;

import com.opensymphony.xwork2.ModelDriven;

import com.siwuxie095.entity.User;

import com.siwuxie095.service.UserService;

 
 

public class UserAction extends ActionSupport implements ModelDriven<User> {

 
 

private User user=new User();

 

@Override

public User getModel() {

return user;

}

 

private UserService userService;

 

public
void setUserService(UserService userService) {

this.userService = userService;

}

 

public String add() {

userService.add(user);

return
"add";

}

 
 

}

 
 

 
 

 
 

(4)拆分后的
Spring 核心配置文件

 
 

applicationContext-action.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:aop="http://www.springframework.org/schema/aop"

xmlns:context="http://www.springframework.org/schema/context"

xmlns:tx="http://www.springframework.org/schema/tx"

xsi:schemaLocation="

http://www.springframework.org/schema/beans

http://www.springframework.org/schema/beans/spring-beans.xsd

http://www.springframework.org/schema/aop

http://www.springframework.org/schema/aop/spring-aop.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">

 

 

<!-- 配置 Action 对象 -->

<!--

注意:由于 Action 对象是多实例的,所以服务器启动时,

不会被创建,只有在访问时,才会被创建

-->

<bean
id="userAction"
class="com.siwuxie095.action.UserAction"
scope="prototype">

<property
name="userService"
ref="userService"></property>

</bean>

 

 

</beans>

 
 

 
 

 

(5)Struts2 核心配置文件

 
 

struts.xml:

 
 

<?xml
version="1.0"
encoding="UTF-8"
?>

<!DOCTYPE struts PUBLIC

"-//Apache Software Foundation//DTD Struts Configuration 2.3//EN"

"http://struts.apache.org/dtds/struts-2.3.dtd">

 
 

<struts>

 

<package
name="demo"
extends="struts-default"
namespace="/">

 

<action
name="user_*"
class="userAction"
method="{1}">

<result
name="add">/succ.jsp</result>

</action>

 

</package>

 
 

</struts>

 
 

 
 

 
 

(6)部署描述文件

 
 

web.xml:

 
 

<?xml
version="1.0"
encoding="UTF-8"?>

<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns="http://java.sun.com/xml/ns/javaee" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"
version="2.5">

<display-name>ssh-web</display-name>

<welcome-file-list>

<welcome-file>index.html</welcome-file>

<welcome-file>index.htm</welcome-file>

<welcome-file>index.jsp</welcome-file>

<welcome-file>default.html</welcome-file>

<welcome-file>default.htm</welcome-file>

<welcome-file>default.jsp</welcome-file>

</welcome-file-list>

 

<!-- 配置 Struts2 的核心过滤器 -->

<filter>

<filter-name>struts2</filter-name>

<filter-class>org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter</filter-class>

</filter>

 

<filter-mapping>

<filter-name>struts2</filter-name>

<url-pattern>/*</url-pattern>

</filter-mapping>

 

<!-- 配置 Spring 的监听器 ContextLoaderListener -->

<listener>

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

</listener>

 

<!--

配置 Spring 核心配置文件的位置(路径)

 

classpath 和 classpath* 的区别:

(1) classpath 只会到指定的 class 路径下查找文件

(2) classpath* 不仅包括 class 路径,还包括 jar 包中,都会去查找文件

 

applicationContext-*.xml 即
以 applicationContext- 开头的 xml 文件,* 为通配符

-->

<context-param>

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

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

</context-param>

 

</web-app>

 
 

 
 

 
 

 
 

13、至此,父项目和子模块创建完毕。父项目此时的目录

结构如下:

 
 

Maven项目的拆分与聚合

 
 

 
 

 
 

 
 

14、将父项目安装(install)到本地仓库中,否则子模块

之间的依赖无法生效。当然,也可按照创建顺序,依次将

父项目和子模块安装到本地仓库

 
 

 
 

 
 

 
 

15、最后,运行项目的两种方式

 
 

(1)运行父项目
ssh-parent(建议)

 
 

父项目
ssh-parent 将子模块聚合到一起。如果子模块内容有

所修改,不必立即安装到本地仓库,父项目将自动聚合并使用

最新代码执行

 
 

 
 

(2)运行子模块
ssh-web

 
 

子模块
ssh-web 将从本地仓库下载依赖的 jar 包,如果依赖

的其它子模块内容有所修改,必须及时安装到本地仓库

 
 

 
 

 
 

 
 

16、访问路径

 
 

http://localhost:8080/ssh-web/add.jsp

 
 

 
 

 
 

 
 

 
 

 
 

 
 

 
 

 
 

 
 

【made by siwuxie095】