java项目开发实战--使用ssm框架开发众筹网站(IDEA版)

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

在这里插入图片描述

  • 修改路径
    在这里插入图片描述

具体代码

  • 我的环境
  1. IDEA 2018
  2. JDK1.8
  3. 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>
  • 5
    点赞
  • 6
    收藏
    觉得还不错? 一键收藏
  • 4
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 4
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值