Intellij搭建springmvc常見(jiàn)問(wèn)題解決方案
注意是maven的webapp:


選擇maven下一步下一步。
maven下載過(guò)慢在setting中加入鏡像。 我也有疑問(wèn)這是什么鬼格式,但是證明,格式不用調(diào)整,直接粘貼進(jìn)去:
<mirror>
<id>
nexus-aliyun
</id>
<mirrorOf>
*
</mirrorOf>
<name>
Nexus aliyun
</name>
<url>
http://maven.aliyun.com/nexus/content/groups/public
</url>
</mirror>
我在這里踩了一個(gè)特郁悶的坑,注意看這里,沒(méi)有package war, 這里有毒,導(dǎo)致我的tomcat一直加不進(jìn)去artifacts

暫時(shí)就是這個(gè)鬼樣子的結(jié)構(gòu),手動(dòng)補(bǔ)全結(jié)構(gòu),

調(diào)整一下包:

加入和pom中的依賴 和 web.xml和 springmvc.xml
注意這里別丟了 pom:

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">
<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:
<?xml version="1.0" encoding="UTF-8"?>
<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:
<?xml version="1.0" encoding="UTF-8"?>
<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>
<!--能訪問(wèn)到靜態(tài)資源,但是URL和控制器中對(duì)應(yīng)的方法沒(méi)有映射關(guān)系-->
<mvc:default-servlet-handler/>
<mvc:annotation-driven></mvc:annotation-driven>
</beans>
這已經(jīng)是很精簡(jiǎn)版的了。

配置tomcat, 我在這里遇到了問(wèn)題,記錄詳細(xì)點(diǎn):






(上面刪除了mymvc:war也是可以的。圖就懶得替換了。)
ok
啟動(dòng)tomcat成功:

而且注意這里不要用http://localhost:8080/ 去試,會(huì)404.
以上就是本文的全部?jī)?nèi)容,希望對(duì)大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。
- IntelliJ IDEA基于SpringBoot如何搭建SSM開(kāi)發(fā)環(huán)境的步驟詳解
- IntelliJ IDEA 的 Spring 項(xiàng)目如何查看 @Value 的配置和值(方法詳解)
- Intellij IDEA基于Springboot的遠(yuǎn)程調(diào)試(圖文)
- Intellij IDEA下Spring Boot熱切換配置
- SpringBoot項(xiàng)目在IntelliJ IDEA中如何實(shí)現(xiàn)熱部署
- Intellij IDEA實(shí)現(xiàn)SpringBoot項(xiàng)目多端口啟動(dòng)的兩種方法
- IntelliJ IDEA maven 構(gòu)建簡(jiǎn)單springmvc項(xiàng)目(圖文教程)
- intellij IDEA配置springboot的圖文教程
- IntelliJ Idea SpringBoot 數(shù)據(jù)庫(kù)增刪改查實(shí)例詳解
- IntelliJ IDEA 創(chuàng)建spring boot 的Hello World 項(xiàng)目(圖解)
相關(guān)文章
Java中的HttpServletRequestWrapper用法解析
這篇文章主要介紹了Java中的HttpServletRequestWrapper用法解析,HttpServletRequest 對(duì)參數(shù)值的獲取實(shí)際調(diào)的是org.apache.catalina.connector.Request,沒(méi)有提供對(duì)應(yīng)的set方法修改屬性,所以不能對(duì)前端傳來(lái)的參數(shù)進(jìn)行修改,需要的朋友可以參考下2024-01-01
Java JDK17沒(méi)有源碼的問(wèn)題及解決
這篇文章主要介紹了Java JDK17沒(méi)有源碼的問(wèn)題及解決方案,具有很好的參考價(jià)值,希望對(duì)大家有所幫助,如有錯(cuò)誤或未考慮完全的地方,望不吝賜教2023-11-11
Springboot如何根據(jù)實(shí)體類生成數(shù)據(jù)庫(kù)表
這篇文章主要介紹了Springboot如何根據(jù)實(shí)體類生成數(shù)據(jù)庫(kù)表的操作,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。如有錯(cuò)誤或未考慮完全的地方,望不吝賜教2021-09-09
Mockito 結(jié)合 Springboot 進(jìn)行應(yīng)用測(cè)試的方法詳解
這篇文章主要介紹了Mockito 結(jié)合 Springboot 進(jìn)行應(yīng)用測(cè)試的方法詳解,本文給大家介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或工作具有一定的參考借鑒價(jià)值,需要的朋友可以參考下2020-11-11
SpringCloud Bus如何實(shí)現(xiàn)配置刷新
這篇文章主要介紹了SpringCloud Bus如何實(shí)現(xiàn)配置刷新,文中通過(guò)示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友可以參考下2020-09-09
SpringCloud Eureka服務(wù)的基本配置和操作方法
Eureka是Netflix開(kāi)源的一個(gè)基于REST的服務(wù)治理框架,主要用于實(shí)現(xiàn)微服務(wù)架構(gòu)中的服務(wù)注冊(cè)與發(fā)現(xiàn),Eureka是Netflix開(kāi)源的服務(wù)發(fā)現(xiàn)框架,用于在分布式系統(tǒng)中實(shí)現(xiàn)服務(wù)的自動(dòng)注冊(cè)與發(fā)現(xiàn),本文介紹SpringCloud Eureka服務(wù)的基本配置和操作方法,感興趣的朋友一起看看吧2023-12-12
Jmeter?BlazeMeter實(shí)現(xiàn)web錄制過(guò)程
BlazeMeter是一款與Apache JMeter兼容的chrome插件,采用BlazeMeter可以方便的進(jìn)行流量錄制和腳本生成,作為接口測(cè)試腳本編寫的一個(gè)基礎(chǔ),這篇文章主要介紹了Jmeter?BlazeMeter實(shí)現(xiàn)web錄制,需要的朋友可以參考下2021-12-12

