2016-08-15 17 views
1

フルアノテーションからハーフXMLハーフアノテーション構成に切り替えた後、アプリケーションが動作しなくなりました。すべてのリクエストは404になり、デバッグを試みるとコントローラメソッドは呼び出されませんでした。Spring MVC - コントローラがロードされていない

web.xmlの

<?xml version="1.0" encoding="UTF-8"?> 
<web-app xmlns="http://xmlns.jcp.org/xml/ns/javaee" 
     xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
     xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/web-app_3_1.xsd" 
     version="3.1"> 
    <servlet> 
     <servlet-name>spring-web</servlet-name> 
     <servlet-class> 
      org.springframework.web.servlet.DispatcherServlet 
     </servlet-class> 
     <init-param> 
      <param-name>contextConfigLocation</param-name> 
      <param-value>/WEB-INF/spring-web-servlet.xml</param-value> 
     </init-param> 
     <load-on-startup>1</load-on-startup> 
    </servlet> 

    <servlet-mapping> 
     <servlet-name>spring-web</servlet-name> 
     <url-pattern>/</url-pattern> 
    </servlet-mapping> 

    <jsp-config> 
     <jsp-property-group> 
      <url-pattern>/*</url-pattern> 
      <page-encoding>UTF-8</page-encoding> 
     </jsp-property-group> 
    </jsp-config> 
</web-app> 

春-ウェブ-servlet.xml

<beans xmlns="http://www.springframework.org/schema/beans" 
     xmlns:context="http://www.springframework.org/schema/context" 
     xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
     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/mvc 
     http://www.springframework.org/schema/mvc/spring-mvc.xsd 
     http://www.springframework.org/schema/context 
     http://www.springframework.org/schema/context/spring-context.xsd"> 

    <mvc:annotation-driven /> 
    <!-- Scan the JavaConfig --> 
    <context:component-scan base-package="vn.fpt.fsoft.csms" /> 

</beans> 

WebConfig.java

@Configuration 
@EnableWebMvc 
@ComponentScan(basePackages = "vn.fpt.fsoft.csms") 
public class WebConfig extends WebMvcConfigurerAdapter { 

    @Override 
    public final void addResourceHandlers(final ResourceHandlerRegistry registry) { 
     registry 
       .addResourceHandler("/resources/**") 
       .addResourceLocations("/WEB-INF/resources/"); 
    } 

    @Bean 
    public InternalResourceViewResolver viewResolver() { 
     InternalResourceViewResolver viewResolver = 
       new InternalResourceViewResolver(); 
     viewResolver.setPrefix("/WEB-INF/views/"); 
     viewResolver.setSuffix(".jsp"); 
     return viewResolver; 
    } 
} 

HomeController.java

@Controller 
public class HomeController { 

    @RequestMapping("/") 
    public String index() { 
     System.out.println("elelee"); 
     return "index"; 
    } 

    @RequestMapping("/login") 
    public String login() { 
     return "login"; 
    } 
} 

Tomcatは、私が問題を発見

15-Aug-2016 06:47:44.136 INFO [RMI TCP Connection(2)-127.0.0.1] org.apache.catalina.core.ApplicationContext.log No Spring WebApplicationInitializer types detected on classpath 
15-Aug-2016 06:47:44.871 INFO [RMI TCP Connection(2)-127.0.0.1] org.apache.catalina.core.ApplicationContext.log Initializing Spring FrameworkServlet 'spring-web' 
+0

なぜ半注釈と半XMLベースのアプローチを使用しているのですか? パッケージの構造は何ですか? –

+0

@RavindraDevadiga私は、Java設定でjsp-configの代替手段が見つからなかったので、xml configが嫌いです。この構造は標準のMaven + Web構造にすぎません。ところで、私はを取り除こうとしましたが、すべて正常に動作しましたが、ちょっとそれが必要です。何が間違っているのか分かりません。 –

答えて

1

ログインします。私はちょうどに変更しなければならなかった

<jsp-config> 
    <jsp-property-group> 
     <url-pattern>*.jsp</url-pattern> 
     <page-encoding>UTF-8</page-encoding> 
    </jsp-property-group> 
</jsp-config> 
+0

cool !!!!!!!!!!! –

関連する問題