私はSpringについて学びたいと思っています。私はそれを設定しようとしていますが、Springが私のコントローラを認識していないように見えるので、私が得られないものがあります。なぜSpringがコントローラをスキャンしないのですか?
これは私のweb.xml
<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://xmlns.jcp.org/xml/ns/javaee" xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/web-app_3_1.xsd" id="WebApp_ID" version="3.1">
<display-name>dispatcher</display-name>
<welcome-file-list>
<welcome-file>index.jsp</welcome-file>
</welcome-file-list>
<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>/*</url-pattern>
</servlet-mapping>
</web-app>
で、この1つは、サーブレット
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:mvc="http://www.springframework.org/schema/mvc" xmlns:context="http://www.springframework.org/schema/context"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
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">
<context:component-scan base-package="it.mexpenses.controller" />
<mvc:annotation-driven />
<bean id="viewResolver" class="org.springframework.web.servlet.view.InternalResourceViewResolver">
<property name="prefix" value="/WEB-INF/jsp/"/>
<property name="suffix" value=".jsp"/>
<property name="order" value="1" />
</bean>
</beans>
コントローラーです:あなたがそこにいることがわかります典型的な春MVCアプリで
package it.mexpenses.controller;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.servlet.ModelAndView;
@Controller
public class LoginController {
@GetMapping("/login")
public ModelAndView login() {
User user = loginService.login(username, password);
return new ModelAndView("welcome", "currentUser", null);
}
}
コントローラーを見ますか? beans.xmlを読んでいることを確認しましたか? – eis
なぜあなたはSpringがコントローラを見つけていないと思いますか? –
@eisなぜなら私はtomcatを起動したときにそれに関係する何も表示されないので、私はその呼び出しをしようとします:URI '/ MExpenses/login'を持つHTTP要求のマッピングが見つかりませんでした。 'DispatcherServlet' – untruste