首页 > 新手springMVC遇到问题,求大神指点intellij-idea平台

新手springMVC遇到问题,求大神指点intellij-idea平台

rt,刚学springmvc想试一下,然后。。。

我的配置文件:

mvc-dispatcher-servlet.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
            http://www.springframework.org/schema/context/spring-context.xsd
            http://www.springframework.org/schema/mvc
            http://www.springframework.org/schema/mvc/spring-mvc.xsd">

    <context:annotation-config></context:annotation-config>

    <!--指明 controller 所在包,并扫描其中的注解-->
    <context:component-scan base-package="com.lzq.zsk">
        <context:include-filter type="annotation" expression="org.springframework.stereotype.Controller"></context:include-filter>
    </context:component-scan>


    <!-- 静态资源(js、image等)的访问 -->
    <mvc:default-servlet-handler/>
    <!-- 开启注解 -->
    <mvc:annotation-driven></mvc:annotation-driven>
    <!--ViewResolver 视图解析器-->
    <!--用于支持Servlet、JSP视图解析-->
    <bean class="org.springframework.web.servlet.view.InternalResourceViewResolver">
        <property name="viewClass" value="org.springframework.web.servlet.view.JstlView"></property>
        <property name="prefix" value="/WEB-INF/pages/"></property>
        <property name="suffix" value=".jsp"></property>
    </bean>

</beans>

 MainController.java
 
package com.lzq.zsk.controller;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;

@Controller
@RequestMapping("/hello")
public class MainController {

    @RequestMapping("/mvc")
    public String helloMVC(){
        System.out.println("helo");

        return "home";
    }
}


一个是依赖包的版本问题(高版本名字改了),一个是core的配置不全。


应该是配置的问题,你的web.xml文件呢?

web.xml 有配置 dispatcher-servlet.xml?


怀疑配置问题,可以看下我的Demo http://git.oschina.net/gradle/ssmbootstr...


<listener>
    <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
  </listener>

web.xml少了上面这句,把Spring容器集成到 Web 应用里面


没有包含类文件,项目是maven来建的吗,如果是需要配置pom.xml中的plugin

或者是在下图这个地方导入需要的依赖包(不建议)


试试spring boot吧

【热门文章】
【热门文章】