new Empty Project,并创建八个maven模块
- parent 父工程,聚合其他工程(pom)
- main Web工程,存放所有页面,框架配置文件(war)
- manager-impl 后台管理系统,存放控制器类,业务层实现类(jar)
- manager-api 后台管理系统,存放业务层接口和DAO层接口(jar)
- potal-impl 前台系统,存放控制器类,业务层实现类(jar)
- potal-api 前台系统,存放业务层接口和DAO层接口(jar)
- common 存放所有模块所需要的公共类(jar)
- bean 存放所有模块的实体类(jar)
- 创建8个模块
-
创建main模块
-
之后依次创建其他模块
建立各模块之间的依赖关系(这里开始跟课程有点不一样)
-
如下是课程中,所有模块之间的依赖
-
例:main依赖manager-impl和potal-impl(依赖谁就将谁的坐标放在pom文件)
<!--快捷键ALT+Insert,可选择Dependency选择依赖-->
<dependency>
<groupId>com.atcrowdfunding.maven</groupId>
<artifactId>manager-impl</artifactId>
<version>1.0-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>com.atcrowdfunding.maven</groupId>
<artifactId>potal-impl</artifactId>
<version>1.0-SNAPSHOT</version>
</dependency>
- 但是根据课程导入各模块之间的依赖,并完成其他配置后,启动会报如下错误
org.springframework.web.context.ContextLoader.initWebApplicationContext Context initialization failed
org.springframework.beans.factory.CannotLoadBeanClassException:
Error loading class [com.atcrowdfunding.manager.service.impl.TestServiceImpl]
......
Caused by: java.lang.NoClassDefFoundError: com/atcrowdfunding/manager/service/TestService
......
- 为解决如上错误,我们需要在main模块中导入manager-api和potal-api模块的依赖
<dependency>
<groupId>com.atcrowdfunding.maven</groupId>
<artifactId>manager-api</artifactId>
<version>1.0-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>com.atcrowdfunding.maven</groupId>
<artifactId>potal-api</artifactId>
<version>1.0-SNAPSHOT</version>
</dependency>
将main项目变为web项目
-
鼠标右击,选择open module settings
-
选择web
- 修改路径
具体代码
- 我的环境
- IDEA 2018
- JDK1.8
- MySql5.7
- bean模块的pom.xml文件
<?xml version="1.0" encoding="UTF-8"?>
<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">
<parent>
<artifactId>parent</artifactId>
<groupId>com.atcrowdfunding.maven</groupId>
<version>1.0-SNAPSHOT</version>
<relativePath>../parent/pom.xml</relativePath>
</parent>
<modelVersion>4.0.0</modelVersion>
<artifactId>bean</artifactId>
</project>
- common模块的pom.xml文件
<?xml version="1.0" encoding="UTF-8"?>
<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">
<parent>
<artifactId>parent</artifactId>
<groupId>com.atcrowdfunding.maven</groupId>
<version>1.0-SNAPSHOT</version>
<relativePath>../parent/pom.xml</relativePath>
</parent>
<modelVersion>4.0.0</modelVersion>
<artifactId>common</artifactId>
<dependencies>
<dependency>
<groupId>com.atcrowdfunding.maven</groupId>
<artifactId>bean</artifactId>
<version>1.0-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>servlet-api</artifactId>
<scope>provided</scope><!-- 注意!!!! -->
</dependency>
<dependency>
<groupId>javax.servlet.jsp</groupId>
<artifactId>jsp-api</artifactId>
<scope>provided</scope><!-- 注意!!!! -->
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-core</artifactId>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-context</artifactId>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-beans</artifactId>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-jdbc</artifactId>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-orm</artifactId>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-web</artifactId>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-webmvc</artifactId>
</dependency>
<dependency>
<groupId>com.mchange</groupId>
<artifactId>c3p0</artifactId>
</dependency>
<dependency>
<groupId>cglib</groupId>
<artifactId>cglib</artifactId>
</dependency>
<dependency>
<groupId>org.aspectj</groupId>
<artifactId>aspectjweaver</artifactId>
</dependency>
<!-- Spring整合MyBatis -->
<!-- MyBatis中延迟加载需要使用Cglib -->
<!-- https://mvnrepository.com/artifact/org.mybatis/mybatis -->
<dependency>
<groupId>org.mybatis</groupId>
<artifactId>mybatis</artifactId>
</dependency>
<dependency>
<groupId>org.mybatis</groupId>
<artifactId>mybatis-spring</artifactId>
</dependency>
<dependency>
<groupId>org.mybatis</groupId>
<artifactId>ibatis-core</artifactId>
</dependency>
<!-- 控制日志输出:结合log4j -->
<dependency>
<groupId>log4j</groupId>
<artifactId>log4j</artifactId>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-log4j12</artifactId>
</dependency>
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
</dependency>
<dependency>
<groupId>jstl</groupId>
<artifactId>jstl</artifactId>
</dependency>
<!-- ********其他****************************** -->
<!-- Ehcache二级缓存 -->
<dependency>