首页新闻找找看学习计划

[IntelliJ IDEA]无法进入SpringMvc的Controller

0
[已关闭问题] 关闭于 2016-10-25 00:08

使用的IntelliJ IDEA+Maven+SpringMvc+Mybatis等搭建的JavaWeb项目,添加Controller却无法访问,提示:no URL paths identified。

项目能够正常启动无报错,整合配置都是我从eclipse项目中复制的,配置应该都没问题,可能是IntelliJ需要设置什么,望大神看看

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">
  <display-name>SimpleLeaveSystem</display-name>
  <welcome-file-list>
    <welcome-file>default.jsp</welcome-file>
  </welcome-file-list>
 
  <!-- 配置springmvc前端控制器 -->
  <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:spring/springmvc.xml</param-value>
    </init-param>
  </servlet>
  <servlet-mapping>
    <servlet-name>springmvc</servlet-name>
    <url-pattern>/</url-pattern>
  </servlet-mapping>
  <context-param>
    <param-name>contextConfigLocation</param-name>
    <param-value>classpath:spring/applicationContext-*.xml</param-value>
    <!-- <param-value>/WEB-INF/classes/spring/applicationContext-*.xml</param-value> -->
  </context-param>
  <listener>
    <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
  </listener>
  <!-- /配置springmvc前端控制器 -->
 
  <!-- 防止spring内存溢出监听器,比如quartz -->
  <listener>
    <listener-class>org.springframework.web.util.IntrospectorCleanupListener</listener-class>
  </listener>
 
  <!-- 设计路径变量值 -->
  <context-param>
    <param-name>webAppRootKey</param-name>
    <param-value>springmvc.root</param-value>
  </context-param>
 
  <!-- session配置 -->
  <session-config>
    <session-timeout>15</session-timeout>
  </session-config>
 
  <!-- 日志记录 -->
  <context-param>
    <!-- 日志配置文件路径 -->
    <param-name>log4jConfigLocation</param-name>
    <param-value>classpath:log4j.properties</param-value>
  </context-param>
  <context-param>
    <!-- 日志页面的刷新间隔 -->
    <param-name>log4jRefreshInterval</param-name>
    <param-value>6000</param-value>
  </context-param>
  <listener>
    <listener-class>org.springframework.web.util.Log4jConfigListener</listener-class>
  </listener>
  <!-- /日志记录 -->
 
  <!-- Spring字符集过滤器 -->
  <filter>
    <filter-name>SpringEncodingFilter</filter-name>
    <filter-class>org.springframework.web.filter.CharacterEncodingFilter</filter-class>
    <init-param>
      <param-name>encoding</param-name>
      <param-value>UTF-8</param-value>
    </init-param>
    <init-param>
      <param-name>forceEncoding</param-name>
      <param-value>true</param-value>
    </init-param>
  </filter>
  <filter-mapping>
    <filter-name>SpringEncodingFilter</filter-name>
    <url-pattern>/*</url-pattern>
  </filter-mapping>
  <!-- /Spring字符集过滤器 -->
</web-app>

springmvc.xml

<beans xmlns="http://www.springframework.org/schema/beans"
       xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:mvc="http://www.springframework.org/schema/mvc"
       xmlns:context="http://www.springframework.org/schema/context"
       xmlns:aop="http://www.springframework.org/schema/aop" xmlns:tx="http://www.springframework.org/schema/tx"
       xsi:schemaLocation="http://www.springframework.org/schema/beans
        http://www.springframework.org/schema/beans/spring-beans-3.2.xsd
        http://www.springframework.org/schema/mvc
        http://www.springframework.org/schema/mvc/spring-mvc-3.2.xsd
        http://www.springframework.org/schema/context
        http://www.springframework.org/schema/context/spring-context-3.2.xsd
        http://www.springframework.org/schema/aop
        http://www.springframework.org/schema/aop/spring-aop-3.2.xsd
        http://www.springframework.org/schema/tx
        http://www.springframework.org/schema/tx/spring-tx-3.2.xsd ">
 
    <!-- 可以扫描controller、service、... -->
    <context:component-scan base-package="org.ctony.simpleleavesystem.controller" />
    <context:component-scan base-package="org.ctony.simpleleavesystem.service" />
 
    <!-- springmvc 注解驱动 -->
    <mvc:annotation-driven />
 
    <!-- spring系统启动以后,加载该类  -->
    <bean class="org.ctony.simpleleavesystem.listener.InitDataListener"></bean>
 
    <!-- 配置视图解析器 -->
    <bean class="org.springframework.web.servlet.view.InternalResourceViewResolver">
        <!-- 前缀 -->
        <property name="prefix" value="/WEB-INF/views"></property>
        <!-- 后缀 -->
        <property name="suffix" value=".jsp"></property>
    </bean>
 
    <!-- 处理静态资源 -->
    <mvc:resources mapping="/css/**/" location="/css/"/>
    <mvc:resources mapping="/img/**/" location="/img/"/>
    <mvc:resources mapping="/js/**/" location="/js/"/>
    <mvc:resources mapping="/fonts/**/" location="/fonts/"/>
    <mvc:resources mapping="/static/**/" location="/static/"/>
    <!-- 文件上传配置 -->
    <bean id="multipartResolver" class="org.springframework.web.multipart.commons.CommonsMultipartResolver">
        <!-- 默认编码 -->
        <property name="defaultEncoding" value="UTF-8"/>
        <!-- 上传文件大小限制为31M,31*1024*1024 -->
        <property name="maxUploadSize" value="32505856"/>
        <!-- 内存中的最大值 -->
        <property name="maxInMemorySize" value="4096"/>
    </bean>
    <!-- /文件上传配置 -->
</beans>

org.ctony.simpleleavesystem.controller.TestController类:

package org.ctony.simpleleavesystem.controller;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
/**
 * Created by Ctony on 2016/10/24.
 */
@Controller
public class TestController {
 
    @RequestMapping("/index")
    public String index(){
        return "index";
    }
}
Ctony的主页 Ctony | 初学一级 | 园豆:15
提问于:2016-10-24 22:49
< >
分享
所有回答(1)
0

感觉是不是        <!-- 前缀 --> <property name="prefix" value="/WEB-INF/views"></property>的value用"/WEB-INF/views/", 你可以debug下看是否能否进入TestController这个类中,

下面这个链接的问题希望对你能有帮助

http://dashen100.com/question/998

wingger | 园豆:211 (菜鸟二级) | 2016-11-09 14:36
清除回答草稿
   您需要登录以后才能回答,未注册用户请先注册