Java dispatcher servlet中没有uri为的http请求
我正在使用SpringMVC开发一个web应用程序,我是spring的新手。我在名为“mvc dispatcher”的DispatcherServlet中发现了一个异常,说明Java dispatcher servlet中没有uri为的http请求,java,xml,jsp,maven,spring-mvc,Java,Xml,Jsp,Maven,Spring Mvc,我正在使用SpringMVC开发一个web应用程序,我是spring的新手。我在名为“mvc dispatcher”的DispatcherServlet中发现了一个异常,说明未找到URI为[/SpringMVCSecurityXML/userinfo]的HTTP请求的映射。我引用了一些类似的问题,但无法找出哪里出了问题。有人能帮我解决吗。我在身份验证完成后得到错误 mvc调度程序servlet <beans xmlns="http://www.springframework.org/sch
未找到URI为[/SpringMVCSecurityXML/userinfo]的HTTP请求的映射。
我引用了一些类似的问题,但无法找出哪里出了问题。有人能帮我解决吗。我在身份验证完成后得到错误
mvc调度程序servlet
<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"
xsi:schemaLocation="
http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-4.1.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context-4.1.xsd">
<context:component-scan base-package="org.o7planning.tutorial.springmvcsecurity.controller" />
<bean
class="org.springframework.web.servlet.view.InternalResourceViewResolver">
<property name="prefix">
<value>/WEB-INF/pages/</value>
</property>
<property name="suffix">
<value>.jsp</value>
</property>
</bean>
/WEB-INF/pages/
.jsp
data-source-cfg.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"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-4.1.xsd">
<bean id="myDataSource"
class="org.springframework.jdbc.datasource.DriverManagerDataSource">
<property name="driverClassName" value="com.mysql.jdbc.Driver" />
<property name="url" value="jdbc:mysql:" />
<property name="username" value="****" />
<property name="password" value="***" />
</bean>
</beans>
spring-security.xml
<?xml version="1.0" encoding="UTF-8"?>
<beans:beans xmlns="http://www.springframework.org/schema/security"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:beans="http://www.springframework.org/schema/beans"
xsi:schemaLocation="http://www.springframework.org/schema/security
http://www.springframework.org/schema/security/spring-security-3.2.xsd
http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-4.1.xsd">
<http use-expressions="true">
<intercept-url pattern="/" access="isAnonymous()" />
<intercept-url pattern="/welcome" access="isAnonymous()" />
<intercept-url pattern="/login" access="isAnonymous()" />
<intercept-url pattern="/logout" access="isAnonymous()" />
<intercept-url pattern="/userInfo"
access="hasAnyRole('ROLE_USER', 'ROLE_ADMIN')" />
<intercept-url pattern="/admin" access="hasRole('ROLE_ADMIN')" />
<intercept-url pattern="/other/**" access="isAuthenticated()" />
<access-denied-handler error-page="/403" />
<form-login login-page='/login' login-processing-url="/j_spring_security_check"
default-target-url="/userInfo" always-use-default-target="false"
authentication-failure-url="/login?error=true" username-parameter="username"
password-parameter="password" />
<logout logout-url="/logout" logout-success-url="/logoutSuccessful"
delete-cookies="JSESSIONID" invalidate-session="true" />
</http>
<authentication-manager>
<authentication-provider>
<user-service>
<user name="user1" password="12345" authorities="ROLE_USER" />
<user name="admin1" password="12345" authorities="ROLE_USER, ROLE_ADMIN" />
</user-service>
</authentication-provider>
<!-- authentication from database -->
<authentication-provider>
<jdbc-user-service data-source-ref="myDataSource"
users-by-username-query="select * from USERS where USERNAME=?"
authorities-by-username-query="select * from USERS where USERNAME=?" />
</authentication-provider>
</authentication-manager>
</beans:beans>
控制器级别缺少@RequestMapping
@Controller
@RequestMapping("/test")
public class MainController {
您的url将是:
/SpringMVCSecurityXML/test/userinfo]尝试将
添加到mvc dispatcher servlet配置中
<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/mvc http://www.springframework.org/schema/mvc/spring-mvc.xsd
http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-4.1.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context-4.1.xsd">
<mvc:annotation-driven/>
<context:component-scan base-package="org.o7planning.tutorial.springmvcsecurity.controller" />
确保导入xmlns:mvc
希望这能对您有所帮助。您能更具体一点吗?因为我猜我在主控制器中有所有的RequestMapping。你能解决你的问题吗?非常感谢,现在它可以工作了。但是如果试图从头开始运行项目,它也会再次抛出相同的错误。你说的从头开始项目是什么意思?我的意思是当我关闭eclipse并重新启动IDE并运行项目时,它会弹出相同的错误。
package org.o7planning.tutorial.springmvcsecurity.controller;
import java.security.Principal;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
@Controller
public class MainController {
@RequestMapping(value = { "/", "/welcome" }, method = RequestMethod.GET)
public String welcomePage(Model model) {
model.addAttribute("title", "Welcome");
model.addAttribute("message", "This is welcome page!");
return "welcomePage";
}
@RequestMapping(value = "/admin", method = RequestMethod.GET)
public String adminPage(Model model) {
model.addAttribute("title", "Admin");
model.addAttribute("message", "Admin Page - This is protected page!");
return "adminPage";
}
@RequestMapping(value = "/login", method = RequestMethod.GET)
public String loginPage(Model model) {
model.addAttribute("title", "Login");
model.addAttribute("message", "Enter your username/password:");
return "loginPage";
}
@RequestMapping(value = "/logoutSuccessful", method = RequestMethod.GET)
public String logoutSuccessfulPage(Model model) {
model.addAttribute("title", "Logout");
return "logoutSuccessfulPage";
}
@RequestMapping(value = "/userInfo", method = RequestMethod.GET)
public String loginPage(Model model, Principal principal) {
model.addAttribute("title", "User Info");
// Sau khi user login thanh cong se co principal
String userName = principal.getName();
model.addAttribute("message",
"User Info - This is protected page!. Hello " + userName);
return "userInfoPage";
}
@RequestMapping(value = "/403", method = RequestMethod.GET)
public String accessDenied(Model model, Principal principal) {
model.addAttribute("title", "Access Denied!");
if (principal != null) {
model.addAttribute("message", "Hi " + principal.getName()
+ "<br> You do not have permission to access this page!");
} else {
model.addAttribute("msg",
"You do not have permission to access this page!");
}
return "403Page";
}
}
<%@taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<%@page session="true"%>
<html>
<head><title>${title}</title></head>
<body>
<h2>Message : ${message}</h2>
<c:if test="${pageContext.request.userPrincipal.name != null}">
<h3>User Info : ${pageContext.request.userPrincipal.name}
| <a href="<c:url value="/logout" />" >Logout</a></h3>
</c:if>
</body>
</html>
@Controller
@RequestMapping("/test")
public class MainController {
<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/mvc http://www.springframework.org/schema/mvc/spring-mvc.xsd
http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-4.1.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context-4.1.xsd">
<mvc:annotation-driven/>
<context:component-scan base-package="org.o7planning.tutorial.springmvcsecurity.controller" />