admin管理员组文章数量:1794759
IntelliJ IDEA下使用默认Spring MVC框架运行失败的解决方案
使用IDEA,直接导入Spring MVC框架
目录结构:
web.xml
<?xml version="1.0" encoding="UTF-8"?> <web-app xmlns="xmlns.jcp/xml/ns/javaee" xmlns:xsi="www.w3/2001/XMLSchema-instance" xsi:schemaLocation="xmlns.jcp/xml/ns/javaee xmlns.jcp/xml/ns/javaee/web-app_3_1.xsd" version="3.1"> <context-param> <param-name>contextConfigLocation</param-name> <param-value>/WEB-INF/applicationContext.xml</param-value> </context-param> <listener> <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class> </listener> <servlet> <servlet-name>dispatcher</servlet-name> <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class> <load-on-startup>1</load-on-startup> </servlet> <servlet-mapping> <servlet-name>dispatcher</servlet-name> <url-pattern>*.do</url-pattern> </servlet-mapping> </web-app>dispatcher-servlet.xml
<?xml version="1.0" encoding="UTF-8"?> <beans xmlns="www.springframework/schema/beans" xmlns:xsi="www.w3/2001/XMLSchema-instance" xmlns:context="www.springframework/schema/context" xmlns:mvc="www.springframework/schema/mvc" xsi:schemaLocation="www.springframework/schema/beans www.springframework/schema/beans/spring-beans.xsd www.springframework/schema/context www.springframework/schema/context/spring-context.xsd www.springframework/schema/mvc www.springframework/schema/mvc/spring-mvc.xsd"> <!-- 使用注解的包,包括子集 --> <context:component-scan base-package="com.wenjiehe.hello"/> <!-- 视图解析器 --> <bean id="viewResolver" class="org.springframework.web.servlet.view.InternalResourceViewResolver"> <property name="prefix" value="/WEB-INF/jsp/" /> <property name="suffix" value=".jsp"/> </bean> </beans>在WEB-INF/jsp目录下创建hello.jsp
<%@ page contentType="text/html;charset=UTF-8" language="java" %> <html> <head> <title>Title</title> </head> <body> ${message} </body> </html>src目录下创建com.wenjiehe.hello.hello.java文件
@Controller @RequestMapping("/hello") public class hello { @RequestMapping(method = RequestMethod.GET ) public String helloWorld(Model model){ model.addAttribute("message", "StringMvc你好啊!"); return "hello"; } }配置好tomcat即可运行,然后遇到一个问题:
28-Apr-2017 20:24:15.997 SEVERE [RMI TCP Connection(3)-127.0.0.1] org.apache.catalina.core.StandardContext.startInternal One or more listeners failed to start. Full details will be found in the appropriate container log file 28-Apr-2017 20:24:15.998 SEVERE [RMI TCP Connection(3)-127.0.0.1] org.apache.catalina.core.StandardContext.startInternal Context [] startup failed due to previous errors这个问题可能出在lib加载的问题,解决办法是把lib文件夹放入WEB-INF目录下,同时添加为library。 问题解决的链接:IntelliJ IDEA 15创建的spring mvc项目无法运行。
这是第一个问题。第二个问题发现重新运行后的程序老是不能更新,找了下解决办法:intellij idea让资源文件自动更新
开始项目中没有 on frame deactivation 选项,在工程名上右击选择Open Module Settings,在Artifacts添加war exploded
至此就可以运行了。
DEMO下载链接:download.csdn/detail/u010873775/9828858
版权声明:本文标题:IntelliJ IDEA下使用默认Spring MVC框架运行失败的解决方案 内容由林淑君副主任自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.xiehuijuan.com/baike/1686618760a86936.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论