Intellij搭建springmvc常见问题解决方案

作者:圣金巫灵 时间:2023-07-23 12:53:29 

注意是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:


<?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>
 <!--能访问到静态资源,但是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.

来源:https://www.cnblogs.com/dayanjing/p/13811739.html

标签:Intellij,搭建,spring,mvc
0
投稿

猜你喜欢

  • Android Lottie实现中秋月饼变明月动画特效实例

    2023-06-19 12:41:17
  • Android使用kotlin实现多行文本上下滚动播放

    2022-05-09 08:08:29
  • WPF实现控件拖动的示例代码

    2023-04-01 09:36:15
  • android实现条目倒计时功能

    2023-08-23 08:35:38
  • Java字母加数字组合比较大小

    2023-02-27 15:27:52
  • .NET的深复制方法(以C#语言为例)

    2022-07-18 00:17:05
  • C#通过NPOI导入导出数据EXCEL

    2023-01-27 14:24:08
  • Java文件操作实例详解

    2023-11-25 10:29:40
  • Android 6.0指纹识别App开发案例

    2021-06-05 10:30:07
  • 使用jpa之动态插入与修改(重写save)

    2021-07-04 21:02:26
  • 创建Android守护进程实例(底层服务)

    2021-11-12 01:37:09
  • Android编程之绘图canvas基本用法示例

    2022-08-21 15:02:23
  • 基于WPF实现简单的文件夹比较工具

    2023-11-15 16:08:34
  • Mybatis实现增删改查(CRUD)实例代码

    2022-10-05 20:03:22
  • Java中两个字符串进行大小比较的方法

    2023-10-12 13:39:26
  • Spring Security实现用户名密码登录详解

    2021-05-24 14:32:36
  • 浅析C# 函数的传值与传址

    2023-11-22 04:46:57
  • 在Flutter中制作翻转卡片动画的完整实例代码

    2023-06-23 23:31:21
  • 带你了解Java常用类小结

    2023-04-15 14:38:26
  • C++类静态成员与类静态成员函数详解

    2022-10-10 08:22:20
  • asp之家 软件编程 m.aspxhome.com