When I'm using InternalResourceViewResolver alone my views will be resolved correctly. When I add annotation-driven to my configuration file, my views are resolved but my resources are not. This is driving me crazy...
src
main
java
resources
css
js
ajaxHandler.js
webapp
WEB-INF
spring
appServlet
servlet-context.xml
views
index.jsp
internalview.jsp
web.xml
Here's my web.xml:
<web-app id="WebApp_ID" version="2.4" xmlns="http://java.sun.com/xml/ns/j2ee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd">
<display-name>spring.introduction</display-name>
<servlet>
<servlet-name>ApplicationServlet</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
<init-param>
<param-name>contextConfigLocation</param-name>
<param-value>/WEB-INF/spring/appServlet/servlet-context.xml</param-value>
</init-param>
</servlet>
<servlet-mapping>
<servlet-name>ApplicationServlet</servlet-name>
<url-pattern>/</url-pattern>
</servlet-mapping>
<welcome-file-list>
<welcome-file>WEB-INF/views/index.jsp</welcome-file>
</welcome-file-list>
</web-app>
The servlet-context.xml:
<?xml version="1.0" encoding="UTF-8"?>
<beans:beans xmlns:beans="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:mvc="http://www.springframework.org/schema/mvc"
xmlns:context="http://www.springframework.org/schema/context"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc-3.0.xsd
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.0.xsd">
<context:component-scan base-package="com.tsystems.sample" />
<beans:bean class="org.springframework.web.servlet.view.InternalResourceViewResolver">
<beans:property name="prefix" value="/WEB-INF/views/" />
<beans:property name="suffix" value=".jsp" />
</beans:bean>
<mvc:resources location="/js/**" mapping="/resources/js/" />
<!--mvc:default-servlet-handler/-->
<mvc:annotation-driven/>
</beans:beans>
The basic flow:
Index.jsp has a form that passes "sender:index" as POST to the indexController. this should fall down to the following method:
#RequestMapping(value = "/Forward", method = RequestMethod.POST)
public ModelAndView forward(#RequestParam(value = "sender", required = true) String sender, Model model) {
m_logger.info(String.format("Captured sender attribute: " + sender));
ModelAndView mav = new ModelAndView("internalview");
mav.addObject("sender", sender);
return mav;
}
This works so far, the info message appears in the server log and the internalview show up. In my internalview.jsp I try to load the js as follows:
<script type="text/javascript" src="<c:url value="/js/ajaxHandler.js"/>"></script>
ending up with a nice 404 error and the message below in the server.log:
[org.springframework.web.servlet.PageNotFound] (default task-20) No mapping found for HTTP request with URI [/spring.introduction/js/ajaxHandler.js] in DispatcherServlet with name 'ApplicationServlet'
If I remove annotation-driven from the config file even my view becomes 404 NOT FOUND. If I remove annotation-driven AND mvc:resources it works but of course the .js is not loaded.
How can I resolve this issue? (There are similar questions as this but after trying out the answers for those, none of them worked so while I accept that the question may be duplicate to others, I'm still opening because none of their answers solves the problem)
Web resources such as JavaScript and CSS should typically be placed under src/main/webapp directory. So in your case (based on your mvc:resources mapping), you should create resources directory in src/main/webapp and move the js and css directories from src/main/resources there.
src/main/webapp/resources/js
src/main/webapp/resources/css
Related
Attempting to create a Spring MVC hello world web app. It is currently returning HTTP Status 404. 404 means it can't find the file, but I'm not sure why. I think my servlet.xml is pointing to the appropriate folder (component-scan). I think all the files are named correctly(no typos). See the picture for the error.
servlet.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"
xmlns:context="http://www.springframework.org/schema/context"
xmlns:mvc="http://www.springframework.org/schema/mvc"
xsi:schemaLocation="
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.xsd
http://www.springframework.org/schema/mvc
http://www.springframework.org/schema/mvc/spring-mvc.xsd">
<context:component-scan base-package="helloworld" />
<mvc:annotation-driven/>
<bean
class="org.springframework.web.servlet.view.InternalResourceViewResolver">
<property name="prefix" value="/WEB-INF/view/" />
<property name="suffix" value=".jsp" />
</bean>
</beans>
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">
<servlet>
<servlet-name>dispatcher</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
<init-param>
<param-name>contextConfigLocation</param-name>
<param-value>/WEB-INF/servlet.xml</param-value>
</init-param>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>dispatcher</servlet-name>
<url-pattern>/</url-pattern>
</servlet-mapping>
</web-app>
HelloWorldController.java
package helloworld;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
#Controller
public class HelloWorldController {
#RequestMapping("/")
public String showPage() {
return "hello-world";
}
}
hello-world.jsp
<!DOCTYPE html>
<html><body>Hello World!</body></html>
The servlet.xml and the web.xml were not under WEB-INF.
The RequestMapping is pointed to "/" in the controller. try making a call to http://localhost:8080/
I am facing java.lang.NoClassDefFoundError: org.springframework.web.servlet.ModelAndView while hitting my JSP page. I have added all the required Jars in WEB-INF/lib folder and also in class-path (META-INF/MANIFEST.MF file) but it does not resolve error.
My WEB.XML is -->
<servlet id="Servlet_13">
<servlet id="Servlet_13">
<servlet-name>spring</servlet-name>
<servlet-class>
org.springframework.web.servlet.DispatcherServlet
</servlet-class>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>spring</servlet-name>
<url-pattern>*.spg</url-pattern>
</servlet-mapping>
<taglib>
<taglib-uri>/WEB-INF/spring.tld</taglib-uri>
<taglib-location>/WEB-INF/spring.tld</taglib-location>
</taglib>
My Spring-Servlet.XML is -->
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:context="http://www.springframework.org/schema/context"
xmlns:p="http://www.springframework.org/schema/p"
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.0.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context-4.0.xsd">
<context:component-scan base-package="com.polaris.*" />
<bean id="viewResolver" class="org.springframework.web.servlet.view.InternalResourceViewResolver">
<property name="prefix">
<value>="/" </value>
</property>
<property name="suffix">
<value>=".jsp" </value>
</property>
</bean>
</beans>
My Java class file is -->
#Controller
#RequestMapping("/BackValuedOffsetChangeEvent.spg")
public class BackValuedOffsetChangeEventAO
{
#RequestMapping(method = { RequestMethod.GET, RequestMethod.POST })
public ModelAndView execute (HttpServletRequest request, HttpServletResponse response,#Validated #ModelAttribute("BackValuedOffsetChangeEvent") BackValuedOffsetChangeEvent BackValuedOffsetChangeEvent)
throws Exception {
// My code
return (new ModelAndView("Success", modelMap));
}
}
Spring Jars added are -->
spring-aop-4.3.1.RELEASE.jar, spring-beans-4.3.1.RELEASE.jar, spring-context-4.3.1.RELEASE.jar, spring-core-4.3.1.RELEASE.jar, spring-expression-4.3.1.RELEASE.jar, spring-web-4.3.1.RELEASE.jar, spring-webmvc-4.3.1.RELEASE.jar
Please note application (EAR file) is deployed on WebSphere environment and Getting Dispatcher class which is in the same Jar file but getting an exception for Model-view class.
Please help to find out the solution. Thanks in advance.
The problem is got resolved after adding JARS in shared Library on Websphere console. Now, it is getting all required JARS. But yet not sure why it is not getting JARS from WEB-INF/lib.
Controller
#Controller
public class Tester {
#RequestMapping(value="testPost", method = RequestMethod.POST)
public ModelAndView testPost(){
ModelAndView _mv = new ModelAndView();
_mv.setViewName("shared/post");
return _mv;
}
}
HTML
<form action="testPost" method="post">
<input type="submit" value="Submit" />
</form>
Web.xml
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://java.sun.com/xml/ns/javaee" xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd" id="WebApp_ID" version="3.0">
<display-name>iCubeHRS</display-name>
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>/WEB-INF/applicationContext.xml</param-value>
</context-param>
<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>
<filter>
<filter-name>site_mesh</filter-name>
<filter-class>org.sitemesh.config.ConfigurableSiteMeshFilter</filter-class>
</filter>
<filter-mapping>
<filter-name>site_mesh</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
<session-config>
<session-timeout>20</session-timeout>
</session-config>
</web-app>
Question
Once set "method" attribute to "POST", when you hit submit button, it always turn into 405 - Request method 'POST' not supported, if delete method attribute from conotroller, and delete method="post" from HTML as well, it works, anyone know how to solve this problem?
Update
I think I found the problem, this issue caused by sitemesh3, after i removed sitemesh3 features from web.xml, POST works fine, but I don't know how to solve it.
I am not sure if this is relevant to your setup but I had the same error (405-post not supported)
Initially I thought it was sitemesh related. However when I looked into it a bit more in my case it was because I was using <mvc:resources /> to provide a static mapping to the decorator.
it was <mvc:resources /> that was not accepting the post requests for the decorator file as sitemesh was trying to access it using a Post request.
I changed the mapping of my decorator file to make sure it was static and responded to POST and GET requests. More details here Spring: not accept POST request under mvc:resources? how to fix that
The code I used is
<bean class="org.springframework.web.servlet.handler.SimpleUrlHandlerMapping">
<property name="urlMap">
<map>
<entry key="/DecTest/**" value="myResourceHandler" />
</map>
</property>
<property name="order" value="100000" />
</bean>
<bean id="myResourceHandler" name="myResourceHandler"
class="org.springframework.web.servlet.resource.ResourceHttpRequestHandler">
<property name="locations" value="/DecTest/" />
<property name="supportedMethods">
<list>
<value>GET</value>
<value>HEAD</value>
<value>POST</value>
</list>
</property>
<!-- cacheSeconds: maybe you should set it to zero because of the posts-->
</bean>
Well as you figured out that the problem was with sitemesh. this link is to a project integrating springMVC with sitemesh
I'm trying to add Apache Tiles to a simple Spring MVC webapp I'm playing with and I can't seem to get it to work (it worked without Tiles). Any request I make gives back 400 bad request, nothing appears in the log (even set to DEBUG) so I'm not sure where to start debbuging. As far as I can tell the Controller mapped method is never called as there's logging in there and it doesn't appear in the log (plus before that I would get a lot of debug info from spring about resolving the mapping to the controller before it was actually called - which now doesn't appear).
My config files are as follows (all under /WEB-INF/):
web.xml:
<?xml version="1.0" encoding="ISO-8859-1" standalone="no"?>
<web-app xmlns="http://java.sun.com/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" version="2.5" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd">
<display-name>myapp</display-name>
<!-- Enable escaping of form submission contents -->
<context-param>
<param-name>defaultHtmlEscape</param-name>
<param-value>true</param-value>
</context-param>
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>classpath*:META-INF/spring/applicationContext*.xml</param-value>
</context-param>
<filter>
<filter-name>CharacterEncodingFilter</filter-name>
<filter-class>org.springframework.web.filter.CharacterEncodingFilter</filter-class>
<init-param>
<param-name>encoding</param-name>
<param-value>UTF-8</param-value>
</init-param>
<init-param>
<param-name>forceEncoding</param-name>
<param-value>true</param-value>
</init-param>
</filter>
<filter>
<filter-name>HttpMethodFilter</filter-name>
<filter-class>org.springframework.web.filter.HiddenHttpMethodFilter</filter-class>
</filter>
<filter-mapping>
<filter-name>CharacterEncodingFilter</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
<filter-mapping>
<filter-name>HttpMethodFilter</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
<!-- Creates the Spring Container shared by all Servlets and Filters -->
<listener>
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>
<!-- Handles Spring requests -->
<servlet>
<servlet-name>myapp</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>myapp</servlet-name>
<url-pattern>/</url-pattern>
</servlet-mapping>
<session-config>
<session-timeout>10</session-timeout>
</session-config>
</web-app>
myapp-servlet.xml:
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:context="http://www.springframework.org/schema/context"
xmlns:mvc="http://www.springframework.org/schema/mvc" xmlns:p="http://www.springframework.org/schema/p"
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-3.1.xsd http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.1.xsd http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc-3.1.xsd">
<!-- The controllers are autodetected POJOs labeled with the #Controller
annotation. -->
<context:component-scan base-package="com.myapp.controller"
use-default-filters="false">
<context:include-filter expression="org.springframework.stereotype.Controller"
type="annotation" />
</context:component-scan>
<!-- Handles HTTP GET requests for /resources/** by efficiently serving
up static resources -->
<mvc:resources location="/resources/" mapping="/resources/**" />
<!-- Allows for mapping the DispatcherServlet to "/" by forwarding static
resource requests to the container's default Servlet -->
<mvc:default-servlet-handler />
<mvc:annotation-driven />
<bean id="tilesConfigurer"
class="org.springframework.web.servlet.view.tiles2.TilesConfigurer">
<property name="definitions">
<list>
<value>/WEB-INF/tiles.xml</value>
</list>
</property>
</bean>
<bean id="viewResolver"
class="org.springframework.web.servlet.view.UrlBasedViewResolver">
<property name="viewClass"
value="org.springframework.web.servlet.view.tiles2.TilesView" />
</bean>
</beans>
tiles.xml
<tiles-definitions>
<definition name="product_detail" template="/WEB-INF/layout/detail.jsp">
<put-attribute name="header" value="/WEB-INF/view/header.jsp" />
<put-attribute name="banner" value="" />
<put-attribute name="body" value="/WEB-INF/view/product.jsp" />
<put-attribute name="footer" value="/WEB-INF/view/footer.jsp" />
</definition>
</tiles-definitions>
The layout just contains one div for each part wrapping a tag. All the views contain simple code like a header or a div.
And for the controller
ProductController.java:
#Controller
#RequestMapping("/product")
public class ProductController {
protected Logger logger = Logger.getLogger(getClass());
#Autowired
private ProductService productService;
#RequestMapping(value = "/{id}", method = RequestMethod.GET)
public ModelAndView getProduct(#PathVariable Long id) {
logger.info("GET product " + id);
Product product = productService.find(id);
ModelAndView mv = new ModelAndView("product_detail", "product", product);
return mv;
}
}
Deploying this with maven embedded tomcat plugin and going to localhost:8080/myapp/product/1 just gives HTTP 400 code without any other indication that something went wrong. There is a product in the DB with that id and everything from the controller down works, as I tried it before adding tiles.
Sorry for the code drop but I can't get this to work for some time now, and I have no idea what else to try or where to start debugging.
Is there some way to force logging what the problem was when a 400 bad request is returned?
You're missing the reference to your myapp-servlet.xml in the servlet configuration.
<!-- Handles Spring requests -->
<servlet>
<servlet-name>myapp</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
<init-param>
<param-name>contextConfigLocation</param-name>
<param-value>WEB-INF/spring/myapp-servlet.xml</param-value>
</init-param>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>myapp</servlet-name>
<url-pattern>/</url-pattern>
</servlet-mapping>
I am trying to integrate Spring Security in my extjs project,but encountered the following error.
The entire stacktrace is.
SEVERE: Exception starting filter springSecurityFilterChain
org.springframework.beans.factory.NoSuchBeanDefinitionException: No bean named 'springSecurityFilterChain' is defined
at org.springframework.beans.factory.support.DefaultListableBeanFactory.getBeanDefinition(DefaultListableBeanFactory.java:510)
at org.springframework.beans.factory.support.AbstractBeanFactory.getMergedLocalBeanDefinition(AbstractBeanFactory.java:1056)
at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:274)
at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:194)
at org.springframework.context.support.AbstractApplicationContext.getBean(AbstractApplicationContext.java:1049)
at org.springframework.web.filter.DelegatingFilterProxy.initDelegate(DelegatingFilterProxy.java:217)
at org.springframework.web.filter.DelegatingFilterProxy.initFilterBean(DelegatingFilterProxy.java:145)
at org.springframework.web.filter.GenericFilterBean.init(GenericFilterBean.java:179)
at org.apache.catalina.core.ApplicationFilterConfig.initFilter(ApplicationFilterConfig.java:269)
at org.apache.catalina.core.ApplicationFilterConfig.getFilter(ApplicationFilterConfig.java:250)
at org.apache.catalina.core.ApplicationFilterConfig.setFilterDef(ApplicationFilterConfig.java:368)
at org.apache.catalina.core.ApplicationFilterConfig.<init>(ApplicationFilterConfig.java:98)
at org.apache.catalina.core.StandardContext.filterStart(StandardContext.java:4211)
at org.apache.catalina.core.StandardContext.startInternal(StandardContext.java:4837)
at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:140)
at org.apache.catalina.core.ContainerBase.startInternal(ContainerBase.java:1028)
at org.apache.catalina.core.StandardHost.startInternal(StandardHost.java:773)
at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:140)
at org.apache.catalina.core.ContainerBase.startInternal(ContainerBase.java:1028)
at org.apache.catalina.core.StandardEngine.startInternal(StandardEngine.java:278)
at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:140)
at org.apache.catalina.core.StandardService.startInternal(StandardService.java:429)
at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:140)
at org.apache.catalina.core.StandardServer.startInternal(StandardServer.java:662)
at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:140)
at org.apache.catalina.startup.Catalina.start(Catalina.java:592)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at org.apache.catalina.startup.Bootstrap.start(Bootstrap.java:290)
at org.apache.catalina.startup.Bootstrap.main(Bootstrap.java:418)
Apr 30, 2012 1:05:00 PM org.apache.catalina.core.StandardContext startInternal
SEVERE: Error filterStart
My web.xml is as follows
<?xml version="1.0" encoding="UTF-8"?>
<web-app id="WebApp_ID" version="2.4"
xmlns="http://java.sun.com/xml/ns/j2ee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd">
<display-name>extjs-crud-grid-spring-hibernate</display-name>
<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>
<listener>
<listener- class>org.springframework.web.context.ContextLoaderListener</listener- class>
</listener>
<servlet>
<servlet-name>extjs-crud-grid-spring-hibernate</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
<init-param>
<param-name>contextConfigLocation</param-name>
<param-value>
/WEB-INF/applicationContext.xml
/WEB-INF/applicationContext-security.xml
</param-value>
</init-param>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>extjs-crud-grid-spring-hibernate</servlet-name>
<url-pattern>*.action</url-pattern>
</servlet-mapping>
applicationContext.xml is
<?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:mvc="http://www.springframework.org/schema/mvc"
xmlns:context="http://www.springframework.org/schema/context"
xsi:schemaLocation="
http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.0.xsd
http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc-3.0.xsd">
<!-- Scans the classpath of this application for #Components to deploy as beans -->
<!-- Annotated controller beans may be defined explicitly, using a standard Spring bean definition in the
dispatcher's context. However, the #Controller stereotype also allows for autodetection, aligned with Spring 2.5's
general support for detecting component classes in the classpath and auto-registering bean definitions for them. -->
<context:component-scan base-package="com.loiane" />
<!-- Configures the #Controller programming model -->
<mvc:annotation-driven />
<!-- misc -->
<bean id="viewResolver" class="org.springframework.web.servlet.view.InternalResourceViewResolver">
<property name="viewClass" value="org.springframework.web.servlet.view.JstlView"/>
<property name="suffix" value=".jsp"/>
</bean>
<!-- Configures Hibernate - Database Config -->
<import resource="db-config.xml" />
applicationContext-security.xml
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:security="http://www.springframework.org/schema/security"
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-2.0.xsd
http://www.springframework.org/schema/security http://www.springframework.org/schema/security/spring-security-2.0.xsd">
<security:global-method-security />
<security:http auto-config="false" entry-point-ref="authenticationProcessingFilterEntryPoint">
<security:intercept-url pattern="/index.jsp" filters="none" />
<security:intercept-url pattern="/*.action" access="ROLE_USER" />
</security:http>
<bean id="authenticationProcessingFilter" class="com.loiane.security.MyAuthenticationProcessingFilter">
<security:custom-filter position="AUTHENTICATION_PROCESSING_FILTER" />
<property name="defaultTargetUrl" value="/index.jsp" />
<property name="authenticationManager" ref="authenticationManager" />
</bean>
<security:authentication-manager alias="authenticationManager" />
<bean id="authenticationProcessingFilterEntryPoint"
class="org.springframework.security.ui.webapp.AuthenticationProcessingFilterEntryPoint">
<property name="loginFormUrl" value="/index.jsp" />
<property name="forceHttps" value="false" />
</bean>
<!--
Usernames/Passwords are
rod/koala
dianne/emu
scott/wombat
peter/opal
These passwords are from spring security app example
-->
<security:authentication-provider>
<security:password-encoder hash="md5"/>
<security:user-service>
<security:user name="options" password="22b5c9accc6e1ba628cedc63a72d57f8" authorities="ROLE_USER" />
</security:user-service>
</security:authentication-provider>
</beans>
I have referred other threads but with no solution.
Can someone correct me where is the problem in the configuration?
Thanks for the time.
EDIT:
A new issue is with mapping.
Here is my controller class.I have my web.xml above.I am using SPring Security.
I am not able to navigate to the main.jsp after successful login.I have added the #RequestMapping annotation above the method.
Controller Class
#Controller
public class ContactController extends MultiActionController {
private ContactService contactService;
#RequestMapping(value="/contact/main.action")
public ModelAndView main(HttpServletRequest request,
HttpServletResponse response) throws Exception {
return new ModelAndView("main.jsp");
}
#RequestMapping(value="/contact/view.action")
public #ResponseBody Map<String,? extends Object> view() throws Exception {
try{
List<Contact> contacts = contactService.getContactList();
return getMap(contacts);
} catch (Exception e) {
return getModelMapError("Error retrieving Contacts from database.");
}
}
#RequestMapping(value="/contact/create.action")
public #ResponseBody Map<String,? extends Object> create(#RequestParam Object data) throws Exception {
try{
List<Contact> contacts = contactService.create(data);
return getMap(contacts);
} catch (Exception e) {
return getModelMapError("Error trying to create contact.");
}
}
About the issue with the controller: you actually don't have a mapping for
/extjs-crud-grid-spring-hibernate/main.action
What you are mapping in that controller is, for example:
/extjs-crud-grid-spring-hibernate/contact/main.action
If you need to access the first URI you should remove "contact" from the controller and only map it with "/main.action".
About Spring Security, I'm sure that this tutorial is useful (or almost any that you can find googling), but if you really want to learn about it, I strongly recommend the Spring books: Spring recipes and Spring Security 3.
try instead of:
<param-value>
/WEB-INF/applicationContext.xml
/WEB-INF/applicationContext-security.xml
</param-value>
to do the following in /WEB-INF/applicationContext.xml:
<import resource="applicationContext-security.xml"/>
I was getting same issue. I tried security:intercept-url pattern="/**" access="ROLE_USER"
Remove criteria on pattern, my problem has been solved. Spring security itself append /spring_security_login url and provide it's login page.
Try it...