溫馨提示×

溫馨提示×

您好,登錄后才能下訂單哦!

密碼登錄×
登錄注冊×
其他方式登錄
點擊 登錄注冊 即表示同意《億速云用戶服務條款》

Intellij搭建springmvc時常見問題的解決方法

發布時間:2020-11-02 15:40:12 來源:億速云 閱讀:231 作者:Leah 欄目:開發技術

本篇文章給大家分享的是有關Intellij搭建springmvc時常見問題的解決方法,小編覺得挺實用的,因此分享給大家學習,希望大家閱讀完這篇文章后可以有所收獲,話不多說,跟著小編一起來看看吧。

注意是maven的webapp:

Intellij搭建springmvc時常見問題的解決方法

Intellij搭建springmvc時常見問題的解決方法

選擇maven下一步下一步。

maven下載過慢在setting中加入鏡像。 我也有疑問這是什么鬼格式,但是證明,格式不用調整,直接粘貼進去:

<mirror>

   <id>
    nexus-aliyun
   </id>
  <mirrorOf>
  *
  </mirrorOf>
  <name>
    Nexus aliyun
  </name>
  <url>
    http://maven.aliyun.com/nexus/content/groups/public
  </url>
</mirror>

我在這里踩了一個特郁悶的坑,注意看這里,沒有package war, 這里有毒,導致我的tomcat一直加不進去artifacts

Intellij搭建springmvc時常見問題的解決方法

暫時就是這個鬼樣子的結構,手動補全結構,

Intellij搭建springmvc時常見問題的解決方法

調整一下包:

Intellij搭建springmvc時常見問題的解決方法

加入和pom中的依賴 和 web.xml和 springmvc.xml

注意這里別丟了 pom:

Intellij搭建springmvc時常見問題的解決方法

pom.xml:

<&#63;xml version="1.0" encoding="UTF-8"&#63;>
<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.shishi</groupId>
  <artifactId>mymvc</artifactId>
  <version>1.0-SNAPSHOT</version>
  <packaging>war</packaging>

  <properties>
    <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
    <maven.compiler.source>1.7</maven.compiler.source>
    <maven.compiler.target>1.7</maven.compiler.target>
    <spring-version>5.2.8.RELEASE</spring-version>
  </properties>

  <dependencies>
    <dependency>
      <groupId>org.springframework</groupId>
      <artifactId>spring-context</artifactId>
      <version>${spring-version}</version>
    </dependency>
    <dependency>
      <groupId>org.springframework</groupId>
      <artifactId>spring-webmvc</artifactId>
      <version>5.2.8.RELEASE</version>
    </dependency>
    <dependency>
      <groupId>commons-logging</groupId>
      <artifactId>commons-logging</artifactId>
      <version>1.2</version>
    </dependency>
    <dependency>
      <groupId>junit</groupId>
      <artifactId>junit</artifactId>
      <version>4.11</version>
      <scope>test</scope>
    </dependency>
    <dependency>
      <groupId>javax.servlet</groupId>
      <artifactId>javax.servlet-api</artifactId>
      <version>4.0.0</version>
      <scope>provided</scope>
    </dependency>
    <dependency>
      <groupId>javax.servlet</groupId>
      <artifactId>jstl</artifactId>
      <version>1.1.1</version>
    </dependency>
    <dependency>
      <groupId>taglibs</groupId>
      <artifactId>standard</artifactId>
      <version>1.1.1</version>
    </dependency>
  </dependencies>
</project>

web.xml:

<&#63;xml version="1.0" encoding="UTF-8"&#63;>
<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_3_0.xsd"
     id="WebApp_ID" version="3.0">
  
  <servlet>
    <servlet-name>SpringMVC</servlet-name>
    <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
    <init-param>
      <param-name>contextConfigLocation</param-name>
      <param-value>classpath:SpringMVC.xml</param-value>
    </init-param>
    <load-on-startup>1</load-on-startup>
  </servlet>
  <servlet-mapping>
    <servlet-name>SpringMVC</servlet-name>
    <url-pattern>/</url-pattern>
  </servlet-mapping>
</web-app>

springmvc.xml:

<&#63;xml version="1.0" encoding="UTF-8"&#63;>
<beans xmlns="http://www.springframework.org/schema/beans"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xmlns:context="http://www.springframework.org/schema/context"
    xmlns:mvc="http://www.springframework.org/schema/mvc"
    xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd http://www.springframework.org/schema/context https://www.springframework.org/schema/context/spring-context.xsd http://www.springframework.org/schema/mvc https://www.springframework.org/schema/mvc/spring-mvc.xsd">

  <context:component-scan base-package="com.springmvc"></context:component-scan>
  <bean id="internalResourceViewResolver" class="org.springframework.web.servlet.view.InternalResourceViewResolver">
    <property name="prefix" value="/jsp/"></property>
    <property name="suffix" value=".jsp"></property>
  </bean>
  <!--能訪問到靜態資源,但是URL和控制器中對應的方法沒有映射關系-->
  <mvc:default-servlet-handler/>
  <mvc:annotation-driven></mvc:annotation-driven>
</beans>

這已經是很精簡版的了。

Intellij搭建springmvc時常見問題的解決方法

配置tomcat, 我在這里遇到了問題,記錄詳細點:

Intellij搭建springmvc時常見問題的解決方法

Intellij搭建springmvc時常見問題的解決方法

Intellij搭建springmvc時常見問題的解決方法

Intellij搭建springmvc時常見問題的解決方法

Intellij搭建springmvc時常見問題的解決方法

Intellij搭建springmvc時常見問題的解決方法

(上面刪除了mymvc:war也是可以的。圖就懶得替換了。)

ok

啟動tomcat成功:

Intellij搭建springmvc時常見問題的解決方法

而且注意這里不要用http://localhost:8080/ 去試,會404.

以上就是Intellij搭建springmvc時常見問題的解決方法,小編相信有部分知識點可能是我們日常工作會見到或用到的。希望你能通過這篇文章學到更多知識。更多詳情敬請關注億速云行業資訊頻道。

向AI問一下細節

免責聲明:本站發布的內容(圖片、視頻和文字)以原創、轉載和分享為主,文章觀點不代表本網站立場,如果涉及侵權請聯系站長郵箱:is@yisu.com進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。

AI

亚洲午夜精品一区二区_中文无码日韩欧免_久久香蕉精品视频_欧美主播一区二区三区美女