我爱编程

SpringMVC: 复旦故事配置

2018-05-27  本文已影响0人  桧天白

晨曦

1. 新建 maven 项目

用Itellij,新建 maven, webapp 项目

1.jpg

点击 next


2.jpg

GroupID 和 artifactId 是新建maven项目的唯一标识,填好后不要改动


然后 next


3.jpg

next

4.jpg

这里是你项目放的地方


配好就finish

5.jpg

注意pom.xml文件里的groupId 和artifactID, 和你前面填的应该一模一样


2. pom.xml 配置

点击右下角的按钮

6.jpg

这样以后有新的maven库配置,它就会自动下载了


7.jpg

注意了
下载初始maven库好了以后,pom.xml就会有上图的数据
不要改它


打开我们项目的pom.xml文件

8.jpg

我们项目的GroupId 和 ArtifactId 和现在新建的不一样对不对
所以我们复制复旦故事项目的 pom.xml 时只能复制 dependency 和 plugin
顺便把 properties 也复制进去

<properties>
    <maven.compiler.source>1.8</maven.compiler.source>
    <maven.compiler.target>1.8</maven.compiler.target>
    <maven.compiler.compilerVersion>1.8</maven.compiler.compilerVersion>
    <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
    <maven.resources.overwrite>true</maven.resources.overwrite>
    <spring.version>4.3.7.RELEASE</spring.version>
    <javax.servlet.version>3.1.0</javax.servlet.version>
    <json.version>20160810</json.version>
    <hibernate.version>5.2.9.Final</hibernate.version>
    <c3p0.version>0.9.5.2</c3p0.version>
    <mysql.version>6.0.6</mysql.version>
    <google.guava.version>18.0</google.guava.version>
    <commons-fileupload.version>1.3.2</commons-fileupload.version>
    <jackson.version>2.8.6</jackson.version>
    <log4j.version>2.7</log4j.version>
  </properties>

  <dependencies>
    <dependency>
      <groupId>junit</groupId>
      <artifactId>junit</artifactId>
      <version>4.11</version>
      <scope>test</scope>
    </dependency>
    <dependency>
      <groupId>org.springframework</groupId>
      <artifactId>spring-aspects</artifactId>
      <version>${spring.version}</version>
    </dependency>
    <dependency>
      <groupId>org.springframework</groupId>
      <artifactId>spring-context-support</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-oxm</artifactId>
      <version>${spring.version}</version>
    </dependency>
    <dependency>
      <groupId>org.springframework</groupId>
      <artifactId>spring-test</artifactId>
      <version>${spring.version}</version>
      <scope>provided</scope>
    </dependency>
    <dependency>
      <groupId>org.springframework</groupId>
      <artifactId>spring-webmvc</artifactId>
      <version>${spring.version}</version>
    </dependency>
    <dependency>
      <groupId>javax.servlet</groupId>
      <artifactId>javax.servlet-api</artifactId>
      <version>${javax.servlet.version}</version>
      <scope>provided</scope>
    </dependency>
    <dependency>
      <groupId>org.json</groupId>
      <artifactId>json</artifactId>
      <version>${json.version}</version>
    </dependency>
    <dependency>
      <groupId>org.hibernate</groupId>
      <artifactId>hibernate-core</artifactId>
      <version>${hibernate.version}</version>
    </dependency>
    <dependency>
      <groupId>com.mchange</groupId>
      <artifactId>c3p0</artifactId>
      <version>${c3p0.version}</version>
    </dependency>
    <dependency>
      <groupId>mysql</groupId>
      <artifactId>mysql-connector-java</artifactId>
      <version>${mysql.version}</version>
    </dependency>
    <dependency>
      <groupId>com.google.guava</groupId>
      <artifactId>guava</artifactId>
      <version>${google.guava.version}</version>
    </dependency>
    <dependency>
      <groupId>com.fasterxml.jackson.core</groupId>
      <artifactId>jackson-databind</artifactId>
      <version>${jackson.version}</version>
    </dependency>
    <dependency>
      <groupId>org.apache.logging.log4j</groupId>
      <artifactId>log4j-core</artifactId>
      <version>${log4j.version}</version>
    </dependency>
    <dependency>
      <groupId>org.apache.commons</groupId>
      <artifactId>commons-lang3</artifactId>
      <version>3.5</version>
    </dependency>
    <dependency>
      <groupId>commons-fileupload</groupId>
      <artifactId>commons-fileupload</artifactId>
      <version>${commons-fileupload.version}</version>
    </dependency>
    <dependency>
      <groupId>cn.sissors</groupId>
      <artifactId>http</artifactId>
      <version>1.0</version>
    </dependency>
    <dependency>
      <groupId>cn.sissors</groupId>
      <artifactId>hql</artifactId>
      <version>1.0</version>
    </dependency>
  </dependencies>

  <build>
    <finalName></finalName> //填你项目的名称
    <resources>
      <resource>
        <directory>src/main/resources</directory>
        <filtering>true</filtering>
        <includes>
          <include>*.properties</include>
          <include>*.xml</include>
          <include>*.ftl</include>
          <include>*.conf</include>
          <include>*.json</include>
        </includes>
      </resource>
    </resources>
    <testResources>
      <testResource>
        <directory>src/main/resources</directory>
        <filtering>true</filtering>
        <includes>
          <include>*.properties</include>
          <include>*.xml</include>
          <include>*.ftl</include>
          <include>*.conf</include>
          <include>*.json</include>
        </includes>
      </testResource>
    </testResources>
    <pluginManagement><!-- lock down plugins versions to avoid using Maven defaults (may be moved to parent pom) -->
      <plugins>
        <plugin>
          <artifactId>maven-clean-plugin</artifactId>
          <version>3.0.0</version>
        </plugin>
        <!-- see http://maven.apache.org/ref/current/maven-core/default-bindings.html#Plugin_bindings_for_war_packaging -->
        <plugin>
          <artifactId>maven-resources-plugin</artifactId>
          <version>3.0.2</version>
        </plugin>
        <plugin>
          <artifactId>maven-compiler-plugin</artifactId>
          <version>3.7.0</version>
        </plugin>
        <plugin>
          <artifactId>maven-surefire-plugin</artifactId>
          <version>2.20.1</version>
        </plugin>
        <plugin>
          <artifactId>maven-war-plugin</artifactId>
          <version>3.2.0</version>
        </plugin>
        <plugin>
          <artifactId>maven-install-plugin</artifactId>
          <version>2.5.2</version>
        </plugin>
        <plugin>
          <artifactId>maven-deploy-plugin</artifactId>
          <version>2.8.2</version>
        </plugin>
          <plugin>
              <groupId>org.apache.tomcat.maven</groupId>
              <artifactId>tomcat7-maven-plugin</artifactId>
              <version>2.2</version>
              <configuration>
                  <url>http://localhost:8080/manager/text</url>
                  <username>zyz</username>
                  <password>1qaz2wsx</password>
                  <path>/story</path>
                  <update>true</update>
              </configuration>
          </plugin>
      </plugins>
    </pluginManagement>
  </build>

这里面是properties、dependency、build的配置,你直接复制粘贴替换掉就行了
里面有一个<finalName></finalName>
这里用你原来的<finalName>xxx</finalName>


等它maven下完

然后把复旦故事项目里的src文件夹复制过来替换掉我们新建的项目的src文件夹

9.jpg

然后你会发现出现问题
没有sources root 文件夹 和 resource 文件夹的标志
这时候你就要手动mark一下
java 文件夹是sources root ,resources 文件夹是 resource

10.jpg

mark好了以后

11.jpg

文件全部配置好了

那么怎么run起来呢


12.jpg

Edit configurations

13.jpg

点击加号,选择 Maven


14.jpg

填上 name : run
Command line : tomcat7:run

然后apply , 再ok


15.jpg

RUN的时候记住连内网

16.jpg

出现红圈里的内容, 说明成功了

然后在浏览器中输入 http://localhost:8080/story

17.jpg

成功配置

教程结束

上一篇下一篇

猜你喜欢

热点阅读