文章详情

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

版权:版权申明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 70068002@qq.com 举报,一经查实,本站将立刻删除。

转载请注明出处:https://www.stntk.com/2617.html/dongtai/houduan/

相关推荐
php数据库怎样去重复的数据
当涉及到数据库去重功能时,PHP可以与数据库交互并执行相应的操作。以下是一个示例的PHP代码,用于从数据库中删除重复的记录并保留唯一的数据:…
头像
后端开发 2024-05-26
1,069
如何在 Python 中使用 try…else 块
在 Python 编程中,我们经常会遇到需要处理异常的情况。使用 try…except 块是一种常见的处理方法,它可以捕获和处理代码中可能出…
头像
后端开发 2024-05-26
1,353
php发送/显示 base64 编码图像
我需要向客户端发送一个 base64 编码的字符串。因此,我打开并读取服务器上的图像文件,对其进行编码并将该数据与 image/jpeg 内…
头像
后端开发 2024-05-26
11,560
php 生成条形码(支持任意php框架)
一:插件安装 在php中我们可以使用php-barcode-generator插件来生成条形码,php-barcode-generator插…
头像
后端开发 2024-05-26
1,020
如何在ThinkPHP6中使用队列技术
ThinkPHP 6(TP6)是一个流行的PHP框架,它提供了一些有用的工具和组件,其中之一就是队列(Queue)服务。队列是一种用于异步处…
头像
后端开发 2024-05-26
1,600
cURL error 60: SSL certificate problem: unable to get local issuer certificate 解决方法
fastadmin开发小程序登录功能报错: cURL error 60: SSL certificate problem: unable t…
头像
后端开发 2024-05-26
1,117
发表评论
暂无评论

还没有评论呢,快来抢沙发~

点击联系客服

在线时间:8:00-16:00

客服电话

400-888-8888

客服邮箱

70068002@qq.com

扫描二维码

关注微信公众号