이것은 duplicate
예상대로 중복 되지 않으며 java.lang.NoSuchMethodError
오류 java.lang.IllegalStateException
가 있으며 다른 용어 인 오류가 발생 합니다.
작업하는 동안 spring-security
오류가 발생합니다.
SEVERE: Exception sending context destroyed event to listener instance of class org.springframework.web.context.ContextLoaderListener
java.lang.IllegalStateException: BeanFactory not initialized or already closed - call 'refresh' before accessing beans via the ApplicationContext
// 나머지 스택 추적
Sep 20, 2016 4:06:34 PM org.apache.coyote.AbstractProtocol start
INFO: Starting ProtocolHandler [http-nio-8080]
Sep 20, 2016 4:06:34 PM org.apache.coyote.AbstractProtocol start
INFO: Starting ProtocolHandler [ajp-nio-8009]
Sep 20, 2016 4:06:34 PM org.apache.catalina.startup.Catalina start
INFO: Server startup in 7520 ms
코드는 다음과 같습니다.
web.xml
<!-- Servlet mapping -->
<servlet>
<servlet-name>dispatcherServlet</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>dispatcherServlet</servlet-name>
<url-pattern>/</url-pattern>
</servlet-mapping>
<!-- context parameters -->
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>/WEB-INF/security-context.xml</param-value>
</context-param>
<listener>
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>
<!-- Filter mappings -->
<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>
security-context.xml
<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" xmlns:security="http://www.springframework.org/schema/security"
xsi:schemaLocation="http://www.springframework.org/schema/mvc
http://www.springframework.org/schema/mvc/spring-mvc-3.2.xsd
http://www.springframework.org/schema/security
http://www.springframework.org/schema/security/spring-security-3.1.xsd
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-3.2.xsd">
<security:http auto-config="true">
<security:intercept-url pattern="/add" access="ROLE_ADMIN" />
<security:form-login login-page="/login"
default-target-url="/add" authentication-failure-url="/loginfailed" />
<security:logout logout-success-url="/logout" />
</security:http>
<security:authentication-manager>
<security:authentication-provider>
<security:user-service>
<security:user name="admin" password="admin"
authorities="ROLE_ADMIN" />
</security:user-service>
</security:authentication-provider>
</security:authentication-manager>
</beans>
dispatcherServlet-servlet.xml
<mvc:annotation-driven />
<context:component-scan base-package="com" />
<bean
class="org.springframework.web.servlet.view.InternalResourceViewResolver">
<property name="prefix" value="/views/" />
<property name="suffix" value=".jsp" />
</bean>
<bean id="messageSource"
class="org.springframework.context.support.ResourceBundleMessageSource">
<property name="basename" value="com/resources/message" />
</bean>
</beans>
참고 이러한 모든 파일은/WEB-INF/
이제 내 구성에 모든 것이 있으므로 오류가 발생하는 이유와 더 많은 구성을 수행하므로 여러 구성 파일을 사용할 것입니다.
도움을 주시면 감사하겠습니다 :)
이 변경 에서 솔루션을 읽은 후 <context-parms>
오류가 해결되지 않았습니다.
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>/WEB-INF/security-context.xml,/WEB-INF/dispatcherServlet-servlet.xml</param-value>
</context-param>
이것은 코드의 다른 부분입니다.
DomainController
@Controller
public class DomainController {
@Autowired
private DomainRepositiry repostiry;
@RequestMapping("/")
public String getHomePage(Model model) {
model.addAttribute("domains", repostiry.getList());
return "indexPage";
}
@RequestMapping(value = "/add", method = RequestMethod.GET)
public String signUp(Model model) {
Domain domain = new Domain();
model.addAttribute("domain", domain);
return "home";
}
@RequestMapping(value = "/add", method = RequestMethod.POST)
public String showResult(@ModelAttribute("domain") Domain domain, BindingResult result) {
String[] supressedFeilds = result.getSuppressedFields();
if (supressedFeilds.length > 0)
throw new RuntimeException("Attempting to bind disallowed feilds ");
repostiry.addToList(domain);
return "redirect:/";
}
@RequestMapping("/detail")
public String getInfoByName(@RequestParam String firstName, Model model) {
model.addAttribute("domain", repostiry.getDomainByFirstName(firstName));
return "detail";
}
@InitBinder
public void initBinder(WebDataBinder binder) {
binder.setDisallowedFields("dateOfBirth");
}
}
LoginController
@Controller
public class LoginContoller {
@RequestMapping(value = "/login", method = RequestMethod.GET)
public String login() {
return "login";
}
@RequestMapping(value = "/loginfailed", method = RequestMethod.GET)
public String loginFailed(Model model) {
model.addAttribute("error", "true");
return "login";
}
@RequestMapping(value = "/logout", method = RequestMethod.GET)
public String logOut(Model model) {
return "login";
}
}
로그인 페이지 로그인 로그인 하려면 자격 증명을 입력하십시오
<c:if test="${not empty error}">
<b><U><spring:message
code="AbstractUserDetailsAuthenticationProvider.badCredentials" /></U></b>
</c:if>
</h1>
<form action='<c:url value="/j_spring_security_check"></c:url>'
method="post">
<h3>
User Name : <br> <input type="text" name=j_username>
<hr>
Password : <br> <input type="text" name="j_password">
<hr>
</h3>
<input type="submit" value="login">
</form>
</body>
</html>
사용자 정보 페이지
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Basic Information</title>
</head>
<body>
<c:forEach var="domain" items="${domains}">
<p>First Name : ${domain.firstName}</p>
<br>
<p>Last Name : ${domain.lastName}</p>
<br>
<p>Number : ${domain.number}</p>
<br>
<p>Date Of Birth : ${domain.dateOfBirth}</p>
<br>
<HR>
<A
href='<spring:url value="/detail?firstName=${domain.firstName}"></spring:url>'>TO
VIEW DETAILS CLICK HERE</A>
<HR>
</c:forEach>
<p>
To add more information <a href='<spring:url value="/add" />'><h2>Click
here</h2></a>
</p>
</body>
</html>
참고 :이 코드는 caused by
예외를 던지지 않고 대신 서버를 원활하게 시작하므로이 error 404
문제를 해결하려고 노력하고 있으므로 도움을 주시면 감사하겠습니다.
이 작업을 마친 후 실제로 사용 하고 파일 과 파일 error
에 jar
버전 충돌 이 있음을 알게되었으며 Prasanna Kumar 가 그의 구성이 작동한다고 말한 것처럼 이유는 모르겠지만 like 를 사용 하면 내 봄 버전 이라는 오류가 발생합니다. 3.1 이상이어야합니다.spring4 jars
spring 3 security jar
context.xsd
context.n.m.xsd
단편 스토리 최종 구성 및 작동 중입니다.
<?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:security="http://www.springframework.org/schema/security"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
http://www.springframework.org/schema/security http://www.springframework.org/schema/security/spring-security-4.1.xsd">
<security:http auto-config="true">
<security:intercept-url pattern="/"
access="hasRole('ROLE_ADMIN')" />
<security:form-login login-page="/login"
default-target-url="/" authentication-failure-url="/loginfailed" />
<security:logout logout-success-url="/logout" />
<security:csrf disabled="true" />
</security:http>
<security:authentication-manager>
<security:authentication-provider>
<security:user-service>
<security:user name="Admin" authorities="ROLE_ADMIN"
password="admin" />
</security:user-service>
</security:authentication-provider>
</security:authentication-manager>
</beans>
추가 정보를 위해 몇 가지 일반적인 오류를 발견했으며 여기에 수정 사항이 있습니다.
1) 오류 Could not verify the provided CSRF token because your session was not found.
<security:csrf disabled="true" />
내부 사용<security-http>
2) 오류 java.lang.IllegalArgumentException: Failed to evaluate expression 'ROLE_ADMIN'
사용 <security:intercept-url pattern="/" access="hasRole('ROLE_ADMIN')" />
하고 <security:authentication-manager>
태그 아래에서 교체 할 필요가 없습니다.
도움이 될 희망
이 기사는 인터넷에서 수집됩니다. 재 인쇄 할 때 출처를 알려주십시오.
침해가 발생한 경우 연락 주시기 바랍니다[email protected] 삭제
몇 마디 만하겠습니다