Advertisement
Guest User

Untitled

a guest
Aug 17th, 2016
141
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 13.49 KB | None | 0 0
  1. SEVERE: Exception sending context initialized event to listener instance of class org.springframework.web.context.ContextLoaderListener
  2. org.springframework.beans.factory.BeanDefinitionStoreException: IOException parsing XML document from ServletContext resource [/WEB-INF/applicationContext.xml]; nested exception is java.io.FileNotFoundException: Could not open ServletContext resource [/WEB-INF/applicationContext.xml]
  3. at org.springframework.beans.factory.xml.XmlBeanDefinitionReader.loadBeanDefinitions(XmlBeanDefinitionReader.java:344)
  4. at org.springframework.beans.factory.xml.XmlBeanDefinitionReader.loadBeanDefinitions(XmlBeanDefinitionReader.java:304)
  5. at org.springframework.beans.factory.support.AbstractBeanDefinitionReader.loadBeanDefinitions(AbstractBeanDefinitionReader.java:181)
  6. at org.springframework.beans.factory.support.AbstractBeanDefinitionReader.loadBeanDefinitions(AbstractBeanDefinitionReader.java:217)
  7. at org.springframework.beans.factory.support.AbstractBeanDefinitionReader.loadBeanDefinitions(AbstractBeanDefinitionReader.java:188)
  8. at org.springframework.web.context.support.XmlWebApplicationContext.loadBeanDefinitions(XmlWebApplicationContext.java:125)
  9. at org.springframework.web.context.support.XmlWebApplicationContext.loadBeanDefinitions(XmlWebApplicationContext.java:94)
  10. at org.springframework.context.support.AbstractRefreshableApplicationContext.refreshBeanFactory(AbstractRefreshableApplicationContext.java:129)
  11. at org.springframework.context.support.AbstractApplicationContext.obtainFreshBeanFactory(AbstractApplicationContext.java:605)
  12. at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:509)
  13. at org.springframework.web.context.ContextLoader.configureAndRefreshWebApplicationContext(ContextLoader.java:446)
  14. at org.springframework.web.context.ContextLoader.initWebApplicationContext(ContextLoader.java:328)
  15. at org.springframework.web.context.ContextLoaderListener.contextInitialized(ContextLoaderListener.java:107)
  16. at org.apache.catalina.core.StandardContext.listenerStart(StandardContext.java:4760)
  17. at org.apache.catalina.core.StandardContext.startInternal(StandardContext.java:5184)
  18. at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:150)
  19. at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1396)
  20. at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1386)
  21. at java.util.concurrent.FutureTask.run(Unknown Source)
  22. at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source)
  23. at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
  24. at java.lang.Thread.run(Unknown Source)
  25. Caused by: java.io.FileNotFoundException: Could not open ServletContext resource [/WEB-INF/applicationContext.xml]
  26. at org.springframework.web.context.support.ServletContextResource.getInputStream(ServletContextResource.java:141)
  27. at org.springframework.beans.factory.xml.XmlBeanDefinitionReader.loadBeanDefinitions(XmlBeanDefinitionReader.java:330)
  28. ... 21 more
  29.  
  30. Aug 17, 2016 2:56:56 PM org.apache.catalina.core.StandardContext startInternal
  31. SEVERE: Error listenerStart
  32. Aug 17, 2016 2:56:56 PM org.apache.catalina.core.StandardContext startInternal
  33. SEVERE: Context [/CustomLoginValidation] startup failed due to previous errors
  34. Aug 17, 2016 2:56:56 PM org.apache.catalina.core.ApplicationContext log
  35. INFO: Closing Spring root WebApplicationContext
  36. Aug 17, 2016 2:56:56 PM org.apache.catalina.core.StandardContext listenerStop
  37. SEVERE: Exception sending context destroyed event to listener instance of class org.springframework.web.context.ContextLoaderListener
  38. java.lang.IllegalStateException: BeanFactory not initialized or already closed - call 'refresh' before accessing beans via the ApplicationContext
  39. at org.springframework.context.support.AbstractRefreshableApplicationContext.getBeanFactory(AbstractRefreshableApplicationContext.java:170)
  40. at org.springframework.context.support.AbstractApplicationContext.destroyBeans(AbstractApplicationContext.java:1000)
  41. at org.springframework.context.support.AbstractApplicationContext.doClose(AbstractApplicationContext.java:976)
  42. at org.springframework.context.support.AbstractApplicationContext.close(AbstractApplicationContext.java:928)
  43. at org.springframework.web.context.ContextLoader.closeWebApplicationContext(ContextLoader.java:583)
  44. at org.springframework.web.context.ContextLoaderListener.contextDestroyed(ContextLoaderListener.java:116)
  45. at org.apache.catalina.core.StandardContext.listenerStop(StandardContext.java:4801)
  46. at org.apache.catalina.core.StandardContext.stopInternal(StandardContext.java:5401)
  47. at org.apache.catalina.util.LifecycleBase.stop(LifecycleBase.java:232)
  48. at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:160)
  49. at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1396)
  50. at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1386)
  51. at java.util.concurrent.FutureTask.run(Unknown Source)
  52. at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source)
  53. at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
  54. at java.lang.Thread.run(Unknown Source)
  55.  
  56. <?xml version="1.0" encoding="UTF-8"?>
  57. <web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  58. xmlns="http://java.sun.com/xml/ns/javaee" xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"
  59. xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd"
  60. id="WebApp_ID" version="3.0">
  61. <display-name>spring_mvc</display-name>
  62. <welcome-file-list><welcome-file>/WEB-INF/jsp/index.jsp</welcome-file> </welcome-file-list>
  63. <!-- Single Servlet -->
  64. <servlet>
  65. <servlet-name>mvc</servlet-name>
  66. <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
  67. <!-- create ds , only app start.. -->
  68. <init-param>
  69. <param-name>contextConfigLocation</param-name>
  70. <param-value>
  71. /WEB-INF/spring-config.xml</param-value>
  72. </init-param>
  73. <load-on-startup>1</load-on-startup>
  74. </servlet>
  75. <servlet-mapping>
  76. <servlet-name>mvc</servlet-name>
  77. <!-- map all action to ds -->
  78. <url-pattern>/</url-pattern>
  79. </servlet-mapping>
  80. <listener>
  81. <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
  82. </listener>
  83.  
  84. <!-- Spring Security Configuration -->
  85. <filter>
  86. <filter-name>springSecurityFilterChain</filter-name>
  87. <filter-class>org.springframework.web.filter.DelegatingFilterProxy</filter-class>
  88. </filter>
  89.  
  90. <filter-mapping>
  91. <filter-name>springSecurityFilterChain</filter-name>
  92. <url-pattern>/*</url-pattern>
  93. </filter-mapping>
  94. </web-app>
  95.  
  96. <?xml version="1.0" encoding="UTF-8"?>
  97. <beans xmlns="http://www.springframework.org/schema/beans"
  98. xmlns:context="http://www.springframework.org/schema/context"
  99. xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  100. xsi:schemaLocation=" http://www.springframework.org/schema/beans
  101. http://www.springframework.org/schema/beans/spring-beans.xsd
  102. http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd">
  103.  
  104.  
  105. <context:component-scan base-package="org.pradeep.demo" />
  106.  
  107. <bean
  108. class="org.springframework.web.servlet.view.InternalResourceViewResolver">
  109. <property name="prefix" value="/WEB-INF/jsp/"></property>
  110. <property name="suffix" value=".jsp"></property>
  111. </bean>
  112. <import resource="SpringSecurity.xml"/>
  113. </beans>
  114.  
  115. <?xml version="1.0" encoding="UTF-8"?>
  116. <bean:beans xmlns="http://www.springframework.org/schema/security"
  117. xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:context="http://www.springframework.org/schema/context"
  118. xmlns:mvc="http://www.springframework.org/schema/mvc" xmlns:bean="http://www.springframework.org/schema/beans"
  119. xsi:schemaLocation="http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc-3.0.xsd
  120. http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
  121. http://www.springframework.org/schema/security http://www.springframework.org/schema/security/spring-security-3.2.xsd
  122. http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-4.0.xsd">
  123.  
  124. <http auto-config="true">
  125. <intercept-url pattern="/admin**" access="ROLE_USER" />
  126. <form-login
  127. login-page="/login"
  128. default-target-url="/welcome"
  129. authentication-failure-url="/login?error"
  130. username-parameter="username"
  131. password-parameter="password" />
  132. <logout logout-success-url="/login?logout" />
  133. <!-- enable csrf protection -->
  134. <csrf/>
  135. </http>
  136.  
  137. <authentication-manager>
  138. <authentication-provider>
  139. <user-service>
  140. <user name="mkyong" password="123456" authorities="ROLE_USER" />
  141. </user-service>
  142. </authentication-provider>
  143. </authentication-manager>
  144. </bean:beans>
  145.  
  146. <%@ page language="java" contentType="text/html; charset=ISO-8859-1"
  147. pageEncoding="ISO-8859-1"%>
  148. <%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
  149. <html>
  150. <head>
  151. <title>Login Page</title>
  152. <style>
  153. .error {
  154. padding: 15px;
  155. margin-bottom: 20px;
  156. border: 1px solid transparent;
  157. border-radius: 4px;
  158. color: #a94442;
  159. background-color: #f2dede;
  160. border-color: #ebccd1;
  161. }
  162.  
  163. .msg {
  164. padding: 15px;
  165. margin-bottom: 20px;
  166. border: 1px solid transparent;
  167. border-radius: 4px;
  168. color: #31708f;
  169. background-color: #d9edf7;
  170. border-color: #bce8f1;
  171. }
  172.  
  173. #login-box {
  174. width: 300px;
  175. padding: 20px;
  176. margin: 100px auto;
  177. background: #fff;
  178. -webkit-border-radius: 2px;
  179. -moz-border-radius: 2px;
  180. border: 1px solid #000;
  181. }
  182. </style>
  183. </head>
  184. <body onload='document.loginForm.username.focus();'>
  185.  
  186. <h1>Spring Security Custom Login Form (Annotation)</h1>
  187.  
  188. <div id="login-box">
  189.  
  190. <h2>Login with Username and Password</h2>
  191.  
  192. <c:if test="${not empty error}">
  193. <div class="error">${error}</div>
  194. </c:if>
  195. <c:if test="${not empty msg}">
  196. <div class="msg">${msg}</div>
  197. </c:if>
  198.  
  199. <form name='loginForm'
  200. action="<c:url value='j_spring_security_check' />" method='POST'>
  201.  
  202. <table>
  203. <tr>
  204. <td>User:</td>
  205. <td><input type='text' name='user' value=''></td>
  206. </tr>
  207. <tr>
  208. <td>Password:</td>
  209. <td><input type='password' name='pass' /></td>
  210. </tr>
  211. <tr>
  212. <td colspan='2'>
  213. <input name="submit" type="submit" value="submit" />
  214. </td>
  215. </tr>
  216. </table>
  217.  
  218. <input type="hidden"
  219. name="${_csrf.parameterName}" value="${_csrf.token}" />
  220. </form>
  221. </div>
  222.  
  223. </body>
  224. </html>
  225.  
  226. package org.pradeep.demo;
  227.  
  228. import org.springframework.stereotype.Controller;
  229. import org.springframework.web.bind.annotation.RequestMapping;
  230. import org.springframework.web.bind.annotation.RequestMethod;
  231. import org.springframework.web.bind.annotation.RequestParam;
  232. import org.springframework.web.servlet.ModelAndView;
  233.  
  234. @Controller
  235. public class HelloController {
  236.  
  237. @RequestMapping(value = { "/", "/welcome**" }, method = RequestMethod.GET)
  238. public ModelAndView welcomePage() {
  239.  
  240. ModelAndView model = new ModelAndView();
  241. model.addObject("title", "Spring Security Custom Login Form");
  242. model.addObject("message", "This is welcome page!");
  243. model.setViewName("hello");
  244. return model;
  245.  
  246. }
  247.  
  248. @RequestMapping(value = "/admin**", method = RequestMethod.GET)
  249. public ModelAndView adminPage() {
  250.  
  251. ModelAndView model = new ModelAndView();
  252. model.addObject("title", "Spring Security Custom Login Form");
  253. model.addObject("message", "This is protected page!");
  254. model.setViewName("admin");
  255.  
  256. return model;
  257.  
  258. }
  259.  
  260. //Spring Security see this :
  261. @RequestMapping(value = "/login", method = RequestMethod.GET)
  262. public ModelAndView login(
  263. @RequestParam(value = "error", required = false) String error,
  264. @RequestParam(value = "logout", required = false) String logout) {
  265.  
  266. ModelAndView model = new ModelAndView();
  267. if (error != null) {
  268. model.addObject("error", "Invalid username and password!");
  269. }
  270.  
  271. if (logout != null) {
  272. model.addObject("msg", "You've been logged out successfully.");
  273. }
  274. model.setViewName("login");
  275.  
  276. return model;
  277.  
  278. }
  279.  
  280. }
  281.  
  282. <?xml version="1.0" encoding="UTF-8"?>
  283. <beans xmlns="http://www.springframework.org/schema/beans"
  284. xmlns:context="http://www.springframework.org/schema/context"
  285. xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  286. xsi:schemaLocation=" http://www.springframework.org/schema/beans
  287. http://www.springframework.org/schema/beans/spring-beans.xsd
  288. http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd">
  289.  
  290. <!-- non web spring beans will go here -->
  291. <import resource="SpringSecurity.xml"/>
  292. </beans>
  293.  
  294. <listener>
  295. <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
  296. </listener>
  297. <context-param>
  298. <param-name>contextConfigLocation</param-name>
  299. <param-value>/WEB-INF/SpringSecurity.xml</param-value>
  300. </context-param>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement