第一天学习SSH,搭建工程和遇到的问题

一、创建一个maven工程如下图结构


创建一个maven工程后,pom.xml配置文件有错误如下

web.xml is missing and <failOnMissingWebXml> is set to true
先不要管!或者在pom.xml中直接加上
 <properties>
    <failOnMissingWebXml>false</failOnMissingWebXml>
  </properties>

完成(等下面配置完成后错误会自动消失闭嘴)

但是webapp里并没有web.xml和WEB-INF,所以需要配置:

    1、右键-属性-Project Facets



点ok,应用并关闭,此时便创建成功web工程需要的文件

为了避免不必要的配置文件错误,继续配置~~

找到window-preferences-Maven-User Setting地址下的配置文件(我并没有找到?!大神请教我找~~)

    (1)在<mirrors></mirrors>中添加阿里云的镜像仓库,下载jar包速度会快很多

<mirror>
 <id>alimaven</id>
    <name>aliyun maven</name>
    <url>http://maven.aliyun.com/nexus/content/groups/public/</url>
    <mirror>central</mirrorOf>
</mirror>

    (2)再在配置文件中添加<profile>标签

<profile>
       <id>jdk1.8</id>
       <activation>
           <activeByDefault>true</activeByDefault>
            <jdk>1.7</jdk>
        </activation>
        <properties>
            <maven.compiler.source>1.7</<maven.compiler.source>
            <maven.compiler.target>1.7</<maven.compiler.target>
            <maven.compiler.compilerVersion>1.7</<maven.compiler.compilerVersion>
        </properties>
</profile>

    2、引入项目依赖的jar包

  • Spring
  • SpringMVC
  • myBatis
  • 数据库连接池,驱动包

打开浏览器搜索maven repository,页面中搜索栏搜索Spring Web MVC ,找到后点标题名进去,选择版本下载,我选择5.0.6版本点进去,点击文本域中代码即复制成功,打开pom.xml,复制进去,错误不要紧,用<dependencies>包裹,保存,网络自动下载,等待即可。

<dependencies>
    <dependency>
        <groupId>org.springframework</groupId>
        <artifactId>spring-webmvc</artifactId>
        <version>5.0.6.RELEASE</version>
    </dependency>
</dependencies>
接着找Spring-JDBC事务控制jar包,搜索Spring-JDBC,版本对应4.3.7,复制。。步骤同上,都是放在 <dependencies>中
<!-- https://mvnrepository.com/artifact/org.springframework/spring-jdbc -->
<dependency>
    <groupId>org.springframework</groupId>
    <artifactId>spring-jdbc</artifactId>
    <version>5.0.6.RELEASE</version>
</dependency>

接着找Spring面向切面编程的  Spring aspects  jar包,版本对应,步骤同上

<!-- https://mvnrepository.com/artifact/org.springframework/spring-aspects -->
<dependency>
    <groupId>org.springframework</groupId>
    <artifactId>spring-aspects</artifactId>
    <version>5.0.6.RELEASE</version>
</dependency>

接下来就是Mybatis的jar包,我选择的是3.4.6版本。。。

<!-- https://mvnrepository.com/artifact/org.mybatis/mybatis -->
<dependency>
    <groupId>org.mybatis</groupId>
    <artifactId>mybatis</artifactId>
    <version>3.4.5</version>
</dependency>

接下来是MyBatis和Spring的适配包。。。

<!-- https://mvnrepository.com/artifact/org.mybatis/mybatis-spring -->
<dependency>
    <groupId>org.mybatis</groupId>
    <artifactId>mybatis-spring</artifactId>
    <version>1.3.1</version>
</dependency>

接下来是数据库连接池,我选择c3p0连接池。。。

<!-- https://mvnrepository.com/artifact/c3p0/c3p0 -->
<dependency>
    <groupId>c3p0</groupId>
    <artifactId>c3p0</artifactId>
    <version>0.9.1.2</version>
</dependency>

接下来是MySQL驱动。。。

<!-- https://mvnrepository.com/artifact/mysql/mysql-connector-java -->
<dependency>
    <groupId>mysql</groupId>
    <artifactId>mysql-connector-java</artifactId>
    <version>5.1.41</version>
</dependency>

若使用其他版本jar包出现miss或无法解析情况就换其他版本,注意版本对应!

项目中的其他jar包用到的引入,jstl,servlet-api,junit

<!-- https://mvnrepository.com/artifact/jstl/jstl -->
    <dependency>
        <groupId>jstl</groupId>
        <artifactId>jstl</artifactId>
        <version>1.2</version>
    </dependency>
<!-- https://mvnrepository.com/artifact/org.mortbay.jetty/servlet-api -->
    <dependency>
        <groupId>org.mortbay.jetty</groupId>
        <artifactId>servlet-api</artifactId>
        <version>3.0.20100224</version>
        <scope>provided</scope>
    </dependency>
<!-- https://mvnrepository.com/artifact/junit/junit -->
    <dependency>
        <groupId>junit</groupId>
        <artifactId>junit</artifactId>
        <version>4.12</version>
        <scope>test</scope>
    </dependency>

猜你喜欢

转载自blog.csdn.net/Colly250/article/details/80643789