I have Quartz 2.2.1 and Spring 3.2.2. app on Eclipse Juno
This is my bean configuration:
<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-3.0.xsd">
<!-- Spring Quartz -->
<bean id="checkAndRouteDocumentsTask" class="net.tce.task.support.CheckAndRouteDocumentsTask" />
<bean name="checkAndRouteDocumentsJob" class="org.springframework.scheduling.quartz.JobDetailFactoryBean">
<property name="jobClass" value="net.tce.task.support.CheckAndRouteDocumentsJob" />
<property name="jobDataAsMap">
<map>
<entry key="checkAndRouteDocumentsTask" value-ref="checkAndRouteDocumentsTask" />
</map>
</property>
<property name="durability" value="true" />
</bean>
<!-- Simple Trigger, run every 30 seconds -->
<bean id="checkAndRouteDocumentsTaskTrigger" class="org.springframework.scheduling.quartz.SimpleTriggerFactoryBean">
<property name="jobDetail" ref="checkAndRouteDocumentsJob" />
<property name="repeatInterval" value="30000" />
<property name="startDelay" value="15000" />
</bean>
<bean class="org.springframework.scheduling.quartz.SchedulerFactoryBean">
<property name="jobDetails">
<list>
<ref bean="checkAndRouteDocumentsJob" />
</list>
</property>
<property name="triggers">
<list>
<ref bean="checkAndRouteDocumentsTaskTrigger" />
</list>
</property>
</bean>
My mvc spring servlet config:
<?xml version="1.0" encoding="UTF-8"?>
<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: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.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">
<bean id="propertyConfigurer"
class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
</bean>
<mvc:annotation-driven />
<context:annotation-config />
<context:component-scan base-package="net.tce" />
<import resource="spring-quartz.xml"/>
</beans>
web.xml
<?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" 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>OperationalTCE</display-name>
<servlet>
<servlet-name>mvc-dispatcher</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
<load-on-startup>0</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>mvc-dispatcher</servlet-name>
<url-pattern>/rest/*</url-pattern>
</servlet-mapping>
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>/WEB-INF/mvc-dispatcher-servlet.xml</param-value>
</context-param>
<listener>
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>
</web-app>
My problem is that always when startup my application, Quartz creates two jobs at the same time. My job must be execute every 30 seconds:
INFO: Starting TASK on Mon Nov 04 15:36:46 CST 2013...
INFO: Starting TASK on Mon Nov 04 15:36:46 CST 2013...
INFO: Starting TASK on Mon Nov 04 15:37:16 CST 2013...
INFO: Starting TASK on Mon Nov 04 15:37:16 CST 2013...
INFO: Starting TASK on Mon Nov 04 15:37:46 CST 2013...
INFO: Starting TASK on Mon Nov 04 15:37:46 CST 2013...
Thanks for your help.
Your ContextLoaderListener and DispatcherServlet are both loading the mvc-dispatcher-servlet.xml. Basically duplicating all your beans resulting in 2 executions as that is also duplicated.
Split your configuration into one that is being loaded by the ContextLoaderListener (containing your services, dao, timers etc.) and one loaded by the DispatcherServlet (containing only web related beans controllers, view resovlers etc.).
Or ditch the ContextLoaderListener altogether and only use the DispatcherServlet to load everything.
Make sure you are not loading both the files in your web.xml file for your project. If you load the spring-quartz.xml file separately, and then load the servlet-config.xml file separately that "imports" the spring-quartz.xml file, then you are loading the file twice which would result in 2 instances of your scheduler. The easy fix would be to either (1) ensure you are not loading spring-quartz.xml in your web.xml file OR (2) remove the import statement in your other xml file.
Updated: Thanks for showing us the web.xml to rule that out. After closer inspection of your xml files, you are setting up the SchedulerFactoryBean with both the job details and the trigger. This is your problem. The job details are included as part of your trigger, so putting them in again causes it to be scheduled twice. Please read the documentation on these two links about the setJobDetails() method:
http://docs.spring.io/spring/docs/2.5.6/api/org/springframework/scheduling/quartz/SchedulerFactoryBean.html
http://docs.spring.io/spring/docs/2.5.6/api/org/springframework/scheduling/quartz/SchedulerAccessor.html#setJobDetails%28org.quartz.JobDetail[]%29
http://docs.spring.io/spring/docs/2.5.6/api/org/springframework/scheduling/quartz/SchedulerAccessor.html#setTriggers%28org.quartz.Trigger[]%29
Excerpt of important info:
setJobDetails
public void setJobDetails(JobDetail[] jobDetails)
Register a list of JobDetail objects with the Scheduler that this FactoryBean creates, to be referenced by Triggers.
This is not necessary when a Trigger determines the JobDetail itself: In this case, the JobDetail will be implicitly registered in combination with the Trigger.
The solution would be to remove the jobDetails from the SchedulerFactoryBean like this:
<bean class="org.springframework.scheduling.quartz.SchedulerFactoryBean">
<property name="triggers">
<list>
<ref bean="checkAndRouteDocumentsTaskTrigger" />
</list>
</property>
</bean>
Related
We have created a Spring mvc portlet with given application context file:
<?xml version="1.0"?>
<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"
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">
<bean id="viewResolver"
class="org.springframework.web.servlet.view.InternalResourceViewResolver">
<property name="contentType" value="text/html;charset=UTF-8" />
<property name="prefix" value="/WEB-INF/" />
<property name="suffix" value=".jsp" />
<property name="viewClass"
value="org.springframework.web.servlet.view.JstlView" />
</bean>
</beans>
On deploying the portlet,the below error message is thrown:
Caused by: org.xml.sax.SAXParseException; lineNumber: 6; columnNumber:
64; cvc-elt.1: Cannot find the declaration of element 'beans'. at
com.sun.org.apache.xerces.internal.util.ErrorHandlerWrapper.createSAXParseException(ErrorHandlerWrapper.java:203)
at
com.sun.org.apache.xerces.internal.util.ErrorHandlerWrapper.error(ErrorHandlerWrapper.java:134)
at
com.sun.org.apache.xerces.internal.impl.XMLErrorReporter.reportError(XMLErrorReporter.java:396)
at
com.sun.org.apache.xerces.internal.impl.XMLErrorReporter.reportError(XMLErrorReporter.java:327)
at
com.sun.org.apache.xerces.internal.impl.XMLErrorReporter.reportError(XMLErrorReporter.java:284)
Caused by:
org.springframework.beans.factory.xml.XmlBeanDefinitionStoreException:
Line 6 in XML document from PortletContext resource
[/WEB-INF/spring/portletpreferences-portlet.xml] is invalid; nested
exception is org.xml.sax.SAXParseException; lineNumber: 6;
columnNumber: 64; cvc-elt.1: Cannot find the declaration of element
'beans'.
The respective spring jars are available to the project as dependencies as shown below:
I have referred all available similar questions to this issue and tried the following:
Adding doctype tag
Removing xsd version
Using an empty elements with beans tag
Are there still any missing dependecies or errors in xml in context xml file.
Update: I have updated both spring beans and spring context jars to same version and also successfullly validated the xml file with xsd definition,but am still getting the same error post deployment.
I have written a Spring MVC application and it failed to get loaded in Tomcat 8.0 and the server throws the below exception. I have tried options like re creating the tomcat instance and the option of deleting the packaged application in maven .m2 directory and installing it again.
From the exception message I am not able to figure out the problem. Can someone help to resolve this. Thank you!
SEVERE: A child container failed during start
java.util.concurrent.ExecutionException: org.apache.catalina.LifecycleException: Failed to start component [StandardEngine[Catalina].StandardHost[localhost].StandardContext[/ftpfiledownload1]]
at java.util.concurrent.FutureTask.report(FutureTask.java:122)
at java.util.concurrent.FutureTask.get(FutureTask.java:192)
at org.apache.catalina.core.ContainerBase.startInternal(ContainerBase.java:939)
at org.apache.catalina.core.StandardHost.startInternal(StandardHost.java:872)
at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:150)
at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1419)
at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1409)
at java.util.concurrent.FutureTask.run(FutureTask.java:266)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)
at java.lang.Thread.run(Thread.java:748)
Caused by: org.apache.catalina.LifecycleException: Failed to start component [StandardEngine[Catalina].StandardHost[localhost].StandardContext[/ftpfiledownload1]]
at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:167)
... 6 more
Caused by: org.apache.catalina.LifecycleException: Failed to start component [org.apache.catalina.webresources.StandardRoot#7ae6cfce]
at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:167)
at org.apache.catalina.core.StandardContext.resourcesStart(StandardContext.java:4860)
at org.apache.catalina.core.StandardContext.startInternal(StandardContext.java:4995)
at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:150)
... 6 more
Caused by: org.apache.catalina.LifecycleException: Failed to initialize component [org.apache.catalina.webresources.JarResourceSet#1c1d8b81]
at org.apache.catalina.util.LifecycleBase.init(LifecycleBase.java:112)
at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:140)
at org.apache.catalina.webresources.StandardRoot.startInternal(StandardRoot.java:724)
at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:150)
... 9 more
Caused by: java.lang.IllegalArgumentException: java.util.zip.ZipException: invalid LOC header (bad signature)
at org.apache.catalina.webresources.AbstractSingleArchiveResourceSet.initInternal(AbstractSingleArchiveResourceSet.java:142)
at org.apache.catalina.util.LifecycleBase.init(LifecycleBase.java:107)
... 12 more
Caused by: java.util.zip.ZipException: invalid LOC header (bad signature)
at java.util.zip.ZipFile.read(Native Method)
at java.util.zip.ZipFile.access$1400(ZipFile.java:60)
at java.util.zip.ZipFile$ZipFileInputStream.read(ZipFile.java:734)
at java.util.zip.ZipFile$ZipFileInflaterInputStream.fill(ZipFile.java:434)
at java.util.zip.InflaterInputStream.read(InflaterInputStream.java:158)
at sun.misc.IOUtils.readFully(IOUtils.java:65)
at java.util.jar.JarFile.getBytes(JarFile.java:425)
at java.util.jar.JarFile.getManifestFromReference(JarFile.java:193)
at java.util.jar.JarFile.getManifest(JarFile.java:180)
at org.apache.catalina.webresources.AbstractSingleArchiveResourceSet.initInternal(AbstractSingleArchiveResourceSet.java:140)
... 13 more
The web.xml file is
<?xml version="1.0" encoding="ISO-8859-1"?>
<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>ftp download - web application</display-name>
<welcome-file-list>
<welcome-file>index.jsp</welcome-file>
</welcome-file-list>
<servlet>
<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>/</url-pattern>
</servlet-mapping>
</web-app>
and servlet.xml is
<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"
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">
<context:component-scan base-package="com.user.test" />
<!-- Controller mapping -->
<bean class="org.springframework.web.servlet.mvc.annotation.AnnotationMethodHandlerAdapter" />
<bean class="org.springframework.web.servlet.mvc.annotation.DefaultAnnotationHandlerMapping" />
<!-- View resolver mapping -->
<bean class="org.springframework.web.servlet.view.InternalResourceViewResolver">
<property name="prefix" value="/WEB-INF/pages/" />
<property name="suffix" value=".jsp" />
</bean>
<!-- message resources -->
<bean id="messageSource" class="org.springframework.context.support.ResourceBundleMessageSource">
<property name="basename" value="messages" />
</bean>
</beans>
0 and have problem where to put public files
I tried Where to place images/CSS in spring-mvc app? this soluion but its not working for me
I have tried to place my public folder every where in WEB-INF directory outside but still nothing
web.xml
<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="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">
<display-name>s-mvc</display-name>
<servlet>
<servlet-name>frontController</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>frontController</servlet-name>
<url-pattern>/</url-pattern>
</servlet-mapping>
<mvc:resources mapping="/css/**" location="/css/"/>
</web-app>
frontcontroller-servlet.xml
<mvc:annotation-driven/>
<context:component-scan base-package="pl.skowronline.controller" />
<bean class="org.springframework.web.servlet.view.InternalResourceViewResolver">
<property name="prefix" value="/WEB-INF/views/"/>
<property name="suffix" value=".jsp"/>
</bean>
and that how I call css file
<link type="text/css" href="/css/bootstrap.css" rel="stylesheet" />
I think you are getting confused with the web.xml and the application-context.xml.
The web.xml should contain the webapp xsd declarations like this, and the mapping for the Dispatcher Servlet.
<?xml version="1.0" encoding="UTF-8"?>
<web-app 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>s-mvc</display-name>
<servlet>
<servlet-name>frontController</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>frontController</servlet-name>
<url-pattern>/</url-pattern>
</servlet-mapping>
</web-app>
Where as the application-context.xml contains the spring-framework xsd declarations like below
<?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/mvc http://www.springframework.org/schema/mvc/spring-mvc-3.0.xsd
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">
<mvc:resources mapping="/css/**" location="/css/"/>
<mvc:annotation-driven />
<context:component-scan base-package="pl.skowronline.controller" />
<bean class="org.springframework.web.servlet.view.InternalResourceViewResolver">
<property name="prefix" value="/WEB-INF/views/"/>
<property name="suffix" value=".jsp"/>
</bean>
</beans>
the answer from JB Nizet is correct. However, it seems the problem of your application is more than just a place to put css/js file. For Spring MVC, you must put all configuration right, or it will not work.
For simplicity, just put the css folder right in the WEB-INF folder (/WEB-INF/css), so that you can access it like this in your page:
<a href="<c:url value='/css/bootstrap.css'/>"
That link should take you directly to the css file. If it works, you can change the <a> tag into the <link> tag for CSS styling.
If it doesn't work, there are a few things to check:
1) Spring Security constraints that forbid you to access the files
2) The affect of various filters/ interceptors that can hinder your file access
3) Servlet Configuration in web.xml. Make sure that no dispatcher intercept your access to the CSS file.
Often, <mvc:resources> will do all the above things for you. But just in case it failed, you may want to have a look.
For the <mvc:resources> error:
The matching wildcard is strict, but no declaration can be found for
element 'mvc:resources'.
It looks like you haven't declared the right schema yet. For example, you should add the following lines in the beginning of your file:
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">
UPDATE:
As your response, the problem seems to be here:
<servlet-mapping>
<servlet-name>frontController</servlet-name>
<url-pattern>/</url-pattern>
</servlet-mapping>
You should change it to:
<servlet-mapping>
<servlet-name>frontController</servlet-name>
<url-pattern>/*.html</url-pattern>
</servlet-mapping>
This will save the URL for the css/images files from conflicting with the URL mapping of controller (your servlet), and it let mvc:resources do it magic. Of course, you can use what ever extension you want for "html" part. For a beautiful URL, we may use a library like Turkey URL rewrite to solve the problem
This is described in the following section of the documentation. Follow the instructions given there, and then change your href: /css/bootstrap.css means: In the folder css right under the root of the server. So, unless your application is deployed as the root application, it won't work, because you need to prepend the context path of your app:
href="<c:url value='/css/bootstrap.css'/>"
And this will thus mean: in the css folder, right under the root of the webapp. If the context path of your webapp is /myFirstWebApp, the generated href will thus be
href="/myFirstWebApp/css/bootstrap.css"
You can try using context path to locate resource files.
<link type="text/css" href="${pageContext.request.contextPath}/css/bootstrap.css" rel="stylesheet" />
Read this to know more.
I too had the same problem.Please perform below steps to get it work which worked well for me and my teammates as well.
Step1 :- Create a folder in Web-INF with name "resources"
Step2 :- Upload your bootstrap,css and js if you already do have or in case if you want to write it write inside this folder
Step3 :- Now Update your dispatcher servlet xml as below
Add Below code within beans tag
<mvc:resources mapping="/resources/**" location="/resources/" />
<mvc:annotation-driven />
Add below code to xsi:schemaLocation at top of this xml
http://www.springframework.org/schema/mvc
http://www.springframework.org/schema/mvc/spring-mvc-4.0.xsd">
step 4:- now you can use css,bootstrap resouces in your code as below
<header class="custem_header_bg"><img src="resources/img/product_banner.png" class="img-responsive"> </header>
You can only set base on JSP as following steps. Then you don't need to set mvc:resources in web.xml.
Just set base as following. Also we can use header file to set this value. Then we can include that header.jsp in to any page we are using in application. Then we dont need to set this value in every JSP.
You need to set <base/> as following...
<c:set var="req" value="${pageContext.request}" />
<c:set var="url"> ${req.requestURL} </c:set>
<c:set var="uri" value="${req.requestURI}" />
<head>
<title></title>
<base href="${fn:substring(url, 0, fn:length(url) - fn:length(uri))}${req.contextPath}/" />
Then You can Import any JS or CSS like below..
<script src="assets/js/angular/angular.js"></script>
I'm developing a software based upon Spring and ICEFaces.
I have a file at <project directory>/src/main/webapp/WEB-INF/views/<filename>.xhtml, that is correctly reached using the following URL: http://<hostname>/<projectname>/<filename>.xhtml
The file contains a <h:form id="formId"> which is rendered as a <form action="/<projectname>/WEB-INF/views/<filename>.xhtml" [.. some other stuff ..]>
It means that, when I click on the input submit contained in the form, the browser tries to open the URL http://<hostname>/<projectname>/WEB-INF/views/<filename>.xhtml and, as I said in the title, it shows an error 404 page.
I'd like that the file .xhtml could be reached using the "longer" URL, too. I'm pretty sure that I'm currently unable to achieve that due to a configuration error.
This is my web.xml:
<?xml version="1.0" encoding="ISO-8859-1"?>
<web-app xmlns="http://java.sun.com/xml/ns/javaee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"
version="2.5">
<web-app>
<display-name>SIGLO</display-name>
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>classpath:applicationContext.xml</param-value>
</context-param>
<listener>
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>
<listener>
<listener-class>org.springframework.web.context.request.RequestContextListener</listener-class>
</listener>
<servlet>
<servlet-name>Faces Servlet</servlet-name>
<servlet-class>javax.faces.webapp.FacesServlet</servlet-class>
<init-param>
<param-name>contextConfigLocation</param-name>
<param-value>classpath:applicationContext.xml</param-value>
</init-param>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet>
<servlet-name>DispatcherServlet</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
<init-param>
<param-name>contextConfigLocation</param-name>
<param-value>classpath:applicationContext.xml</param-value>
</init-param>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>Faces Servlet</servlet-name>
<url-pattern>*.jsf</url-pattern>
</servlet-mapping>
<servlet-mapping>
<servlet-name>DispatcherServlet</servlet-name>
<url-pattern>/</url-pattern>
</servlet-mapping>
</web-app>
This is the applicationContext.xml referenced in the previous file:
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:context="http://www.springframework.org/schema/context"
xmlns:aop="http://www.springframework.org/schema/aop"
xmlns:tx="http://www.springframework.org/schema/tx"
xmlns:mvc="http://www.springframework.org/schema/mvc"
xmlns="http://www.springframework.org/schema/beans"
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/tx
http://www.springframework.org/schema/tx/spring-tx-3.0.xsd
http://www.springframework.org/schema/aop
http://www.springframework.org/schema/aop/spring-aop-3.0.xsd
http://www.springframework.org/schema/mvc
http://www.springframework.org/schema/mvc/spring-mvc-3.0.xsd" >
<context:component-scan base-package="com.infoone.siglo" />
<!--
map all requests to /resources/** to the container default servlet
(ie, don't let Spring handle them)
-->
<bean id="defaultServletHttpRequestHandler" class="org.springframework.web.servlet.resource.DefaultServletHttpRequestHandler" />
<bean id="simpleUrlHandlerMapping" class="org.springframework.web.servlet.handler.SimpleUrlHandlerMapping" >
<property name="urlMap" >
<map>
<entry key="/resources/**" value-ref="defaultServletHttpRequestHandler" />
</map>
</property>
</bean>
<bean class="org.springframework.web.servlet.mvc.HttpRequestHandlerAdapter" />
<mvc:annotation-driven />
<!-- JSF for representation layer. All JSF files under /WEB-INF/views directory -->
<bean id="viewResolver" class="org.springframework.web.servlet.view.UrlBasedViewResolver" >
<property name="cache" value="false" />
<property name="viewClass" value="org.springframework.faces.mvc.JsfView" />
<property name="prefix" value="/WEB-INF/views/" />
<property name="suffix" value=".jsp" />
</bean>
<bean name="icefacesResourceHandler" class="org.springframework.faces.webflow.JsfResourceRequestHandler" />
<bean class="org.springframework.web.servlet.handler.SimpleUrlHandlerMapping">
<property name="order" value="0" />
<property name="mappings">
<value>
/javax.faces.resource/**=icefacesResourceHandler
</value>
</property>
</bean>
</beans>
And, in the end, this is my faces-config.xml:
<?xml version="1.0" encoding="UTF-8"?>
<faces-config version="2.0" xmlns="http://java.sun.com/xml/ns/javaee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee
http://java.sun.com/xml/ns/javaee/web-facesconfig_2_0.xsd">
<application>
<el-resolver>org.springframework.web.jsf.el.SpringBeanFacesELResolver</el-resolver>
<locale-config></locale-config>
<resource-bundle>
<base-name>MessageResources</base-name>
<var>msg</var>
</resource-bundle>
</application>
</faces-config>
Let me point out that this configuration still does not allow me to open successfully the shorter URL. Indeed, I have to create a proper controller or, better, a proper #RequestMapping inside a #Controller:
#RequestMapping(value = "<filename>", method = RequestMethod.GET)
public String creaBlocco()
{
return "<filename>";
}
#RequestMapping(value = "<filename>", method = RequestMethod.POST)
public String creaBlocco([.. parameters ..]) {
[.. stuff ..]
return "<filename>";
}
Yes, the value of the #RequestMapping is "<filename>", without the .xhtml extension. I already made sure, by trial and error, that such mapping is necessary for the GET to be successful. On the other hand, I realize that such configuration is really fragile. What should I change in my config files, in order to make <filename>.xhtml reachable using also the longer URL?
Thanks in advance for your attention.
After some research, I came up with the conclusion that I wasn't using those technologies in the way they're meant to be used. If you're facing my same problem, within the same context, you are probably making my same error, therefore you have to slightly modify your application architecture to solve it. Indeed, it seems that using JSF/ICEFaces and Spring MVC in conjunction with Spring WebFlow is the most comfortable and straightforward approach.
I'll try to explain the rationale.
Your site/user home page is filled up with links to the use cases (or, better, flows) that can be activated with his/her privileges. Those links look like http://<page-url>?<flow-id>. A flow in Spring WebFlow is defined as a graph of states, within an xml file. The transitions between states are labeled by strings, named actions, or conditions. Some states are view-state s, meaning that there's something to show to the user when such a state is reached. Therefore, for each view-state named <state-id>, there shall be an .xhtml file named <state-id>.xhtml.
The buttons provided by JSF and ICEFaces will always be rendered as <input type="submit" [..]> and the action of the containing form will always point to the same URL as the containing page (i.e. http://<page-url>?<flow-id>). That's a fact.
The difference is that, in this case, such URL is not backed by a real file (like in my question) but, if the app is properly configured, a flow-handler will answer and manage all the states and the transitions defined in the xml file, choosing the proper view to show.
Beside that, the buttons provided by JSF and ICEFaces have an action attribute. As you can imagine, they correspond to the actions defined in the flow definition file: therefore, a click on a button with a certain value of the action attribute will trigger the transition from the current state labeled exactly with that string.
Speaking more concretely, if you click on the button, the browser sends a POST request to http://<page-url>?<flow-id> whose body contains all the necessary parameters. The flow handler receives that POST request and computes the next state, possibly choosing which view has to be shown to the user.
If you're still reading this answer, I guess you need a concrete example to refer to. I'll provide you with the one I used to learn all the things I wrote here: http://wiki.icesoft.org/display/ICE/Spring+Web+Flow+2.3.1 It's an awesome starting point, because it's easy but exhaustive.
This may be trivial. But I didn't get any info on this.
Can we have an annotated Controller implementation class and a Controller implementation class that implements Controller interface(or extends AbstractController) in the same web application?
If so what is the way to do it.
I tried writing the following spring context, but the class that implements Controller was never loaded
<?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:lang="http://www.springframework.org/schema/lang"
xmlns:aop="http://www.springframework.org/schema/aop" xmlns:context="http://www.springframework.org/schema/context"
xmlns:mvc="http://www.springframework.org/schema/mvc"
xsi:schemaLocation="http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-3.0.xsd
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/lang http://www.springframework.org/schema/lang/spring-lang-3.0.xsd
http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc-3.0.xsd">
<bean name="/home.htm" class="com.dell.library.web.HomePageController">
<property name="library" ref="library" />
</bean>
<context:component-scan base-package="com.dell.library.web.anot" />
<mvc:annotation-driven />
<bean id="viewResolver"
class="org.springframework.web.servlet.view.InternalResourceViewResolver">
<property name="prefix">
<value>/WEB-INF/jsp/</value>
</property>
<property name="suffix">
<value>.jsp</value>
</property>
</bean>
</beans>
In my case the HomePageController is never loaded.
Is this the right way?
Thanks
Dhanush
<mvc:annotation-driven> effectively disables old controllers. You need to enable them by declaring
<bean class = "org.springframework.web.servlet.handler.BeanNameUrlHandlerMapping" />
<bean class = "org.springframework.web.servlet.mvc.SimpleControllerHandlerAdapter" />
UPDATE: Functionality of DispatcherServlet is controlled by sevaral kinds of strategy classes. In particular, HandlerMapping defines a way to map URLs onto controllers, and HandlerAdapter defines a way to perform a call of particular controller.
So, lines above declare strategies that enable mapping URLs onto bean names and calling Controller classes. Actually, there strategies are enabled by default, but only if no other strategies are declared explicitly. Since <mvc:annotation-driven> declares in own strategies explicitly, you need to declare these beans explicitly as well.
Also see DispatcherServlet javadoc.