Java 我的spring安全配置出了什么问题?
我在运行spring security时遇到异常 原因:org.springframework.expression.spel.SpelEvaluationException:EL1008E:(位置0):在类型为“org.springframework.security.web.access.expression.WebSecurityExpressionRoot”的对象上找不到属性或字段“ROLE\u USER”—可能不是公共的 web.xmlJava 我的spring安全配置出了什么问题?,java,spring,jsp,spring-mvc,spelevaluationexception,Java,Spring,Jsp,Spring Mvc,Spelevaluationexception,我在运行spring security时遇到异常 原因:org.springframework.expression.spel.SpelEvaluationException:EL1008E:(位置0):在类型为“org.springframework.security.web.access.expression.WebSecurityExpressionRoot”的对象上找不到属性或字段“ROLE\u USER”—可能不是公共的 web.xml <?xml version="1.0" e
<?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" version="3.0">
<display-name>Spring MVC Application</display-name>
<servlet>
<servlet-name>mvc-dispatcher</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>mvc-dispatcher</servlet-name>
<url-pattern>/</url-pattern>
</servlet-mapping>
<listener>
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>
/WEB-INF/mvc-dispatcher-servlet.xml,
/WEB-INF/spring-security.xml
</param-value>
</context-param>
<filter>
<filter-name>springSecurityFilterChain</filter-name>
<filter-class>org.springframework.web.filter.DelegatingFilterProxy</filter-class>
</filter>
<filter-mapping>
<filter-name>springSecurityFilterChain</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
</web-app>
home.jsp
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Insert title here</title>
</head>
<body>
<h3>Welcome To Spring Security </h3>
<a href="/SpringSecurity1-FORM/welcome"><b>Click here to logon</b></a>
</body>
</html>
在此处插入标题
欢迎来到春季安全
hello.jsp
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Insert title here</title>
</head>
<body>
<h3>Message : ${message}</h3>
<h3>Username : ${username}</h3>
<a href="<c:url value="/j_spring_security_logout" />" >Logout</a>
</body>
</html>
在此处插入标题
消息:${Message}
用户名:${Username}
试试access=“hasRole('ROLE\u USER')”
。谢谢Attila,它可以工作:)你好Attila Gynongyosi,我又发布了一个关于spring安全性的问题,在这种情况下你能帮我吗!。。试试access=“hasRole('ROLE_USER')”
。谢谢Attila,它可以工作:)你好Attila Gynongyosi,我又发布了一个关于spring安全性的问题,在这种情况下你能帮我吗!。。
package com.springtraining.security.controller;
import java.security.Principal;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
@Controller
public class LoginController
{
public LoginController()
{
System.out.println("LoginController constructor is called ");
}
@RequestMapping(value="/welcome", method=RequestMethod.GET)
public String printWelcome(ModelMap model,Principal principal)
{
System.out.println("**********Login Controller is Called********");
String name= principal.getName();
model.addAttribute("username", name);
model.addAttribute("message", "Spring Security Custom Form Example");
return "hello";
}
@RequestMapping(value="/*",method=RequestMethod.GET)
public String home(ModelMap model)
{
return "home";
}
@RequestMapping(value="/login",method=RequestMethod.GET)
public String login(ModelMap model)
{
return "login";
}
@RequestMapping(value="/test",method=RequestMethod.GET)
public String test(ModelMap model)
{
return "test";
}
}
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Insert title here</title>
</head>
<body>
<h3>Welcome To Spring Security </h3>
<a href="/SpringSecurity1-FORM/welcome"><b>Click here to logon</b></a>
</body>
</html>
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Insert title here</title>
</head>
<body>
<h3>Message : ${message}</h3>
<h3>Username : ${username}</h3>
<a href="<c:url value="/j_spring_security_logout" />" >Logout</a>
</body>
</html>