Thymeleaf template engine swallowing exceptions - spring-mvc

I'm using thymeleaf 2.0.5 with spring 3 mvc configured as follows in webmvc-config.xml
<bean id="templateResolver"
class="org.thymeleaf.templateresolver.ServletContextTemplateResolver"
p:prefix="/WEB-INF/templates/"
p:suffix=".html"
p:templateMode="HTML5" />
<bean id="templateEngine"
class="org.thymeleaf.spring3.SpringTemplateEngine"
p:templateResolver-ref="templateResolver" />
<bean id="viewResolver"
class="org.thymeleaf.spring3.view.ThymeleafViewResolver"
p:templateEngine-ref="templateEngine" />
The above configuration is working fine. The problem is that when an exception is thrown I see the following cryptic message in the logs:
ERROR org.thymeleaf.TemplateEngine - [THYMELEAF][1] Exception processing template "dataAccessFailure": Error resolving template "dataAccessFailure", template might not exist or might not be accessible by any of the configured Template Resolvers
Is there a way to configure the view resolver to exclude certain patterns?
As per the accepted answer I changed the following bean config in webmvc-config.xml
<bean id="viewResolver"
class="org.thymeleaf.spring3.view.ThymeleafViewResolver"
p:templateEngine-ref="templateEngine"
p:viewNames="index,questionnaires/*" />

You can configure your template resolver to only resolve certain view names by means of the template resolver's viewNames property. In this property you can enter several patterns (separated by commas) and use wildcards like e.g. admin/*.
Disclaimer, due to StackOverflow rules: I am thymeleaf's author.

Could you possibly have an error page mapped to "dataAccessFailure" in your web.xml. Something like:
<error-page>
<exception-type>java.lang.Throwable</exception-type>
<location>/dataAccessFailure</location>
</error-page>

Related

Spring Security Active Directory bad credentials handling (error 49)

I have problem with Active Directory authentication in simple Spring web application. I'm using ActiveDirectoryLdapAuthenticationProvider and it seems to work fine for empty login fields and correct credentials. The problem is with invalid credentials (wrong login/pass or both). The application throws exception (error 500) to browser:
Error processing request
Context Path: /MYAPPNAME
Servlet Path: /login_check
Path Info: null
Query String: null
Stack Trace:
org.springframework.ldap.UncategorizedLdapException: Uncategorized exception occured during LDAP processing; nested exception is javax.naming.NamingException: JBAS011843: Failed instantiate InitialContextFactory com.sun.jndi.ldap.LdapCtxFactory from classloader ModuleClassLoader for Module "deployment.MYAPPNAME.war:main" from Service Module Loader [Root exception is javax.naming.AuthenticationException: [LDAP: error code 49 - 80090308: LdapErr: DSID-0C090334, comment: AcceptSecurityContext error, data 52e, vece]] (...)
The console root error is:
javax.naming.AuthenticationException: [LDAP: error code 49 - 80090308:
LdapErr: DSID-0C090334, comment: AcceptSecurityContext error, data 52e, vece]
If the credentials are incorrect, shouldn't Spring send user to authentication-failure-url? I don't have any "manager" account to use for ldap BIND, I believe ActiveDirectoryLdapAuthenticationProvider is supposed to bind using credentials from login form. Spring documentation doesn't have anything about binding to AD.
It can probably be solved using custom authentication provider, but I was hoping there is an out-of-the-box solution. There are some similar questions, but none of them very precise or with any useful answer.
How to approach this error?
Is there a way to configure it in XML? Perhaps, to tell AD provider to tread binding error as failed login attempt?
Is custom authentication provider the only solution?
spring-security.xml
<bean id="roleVoter" class="org.springframework.security.access.vote.RoleVoter">
<property name="rolePrefix" value="" />
</bean>
<bean id="accessDecisionManager" class="org.springframework.security.access.vote.AffirmativeBased">
<constructor-arg name="decisionVoters" ref="roleVoter" />
</bean>
<s:http authentication-manager-ref="ldap-auth" access-decision-manager-ref="accessDecisionManager" use-expressions="false">
<s:intercept-url pattern="/list**" access="ADGROUP-XYZ" />
<s:form-login
login-page="/login"
login-processing-url="/login_check"
username-parameter="username"
password-parameter="password"
default-target-url="/list"
authentication-failure-url="/login?fail" />
<s:logout
invalidate-session="true"
logout-success-url="/login?logout"
logout-url="/logout"
delete-cookies="JSESSIONID" />
<s:csrf />
</s:http>
<s:authentication-manager id="ldap-auth">
<s:authentication-provider ref="adAuthenticationProvider" />
</s:authentication-manager>
<bean id="adAuthenticationProvider" class="org.springframework.security.ldap.authentication.ad.ActiveDirectoryLdapAuthenticationProvider">
<constructor-arg value="company.local" />
<constructor-arg value="ldap://server.company.local:389/" />
<property name="useAuthenticationRequestCredentials" value="true"/>
<property name="convertSubErrorCodesToExceptions" value="true"/>
</bean>
EDIT: One ugly fix is to override ActiveDirectoryLdapAuthenticationProvider and change throw LdapUtils.convertLdapException(e); to throw badCredentials(e);.
There is a issue with JBoss EAP initial context.This has been fixed in the latest wildfly versions.check the below links
https://jira.spring.io/browse/SEC-2754
https://issues.jboss.org/browse/WFLY-4149

Is it possible to configure OpenSessionInViewFilter in Spring application context so that context:property-placeholder is useable?

Initial situation
My web application consists of the Maven modules myapp-persistence(.jar), myapp-model(.jar), myapp-service(.jar) and myapp-web(.war) to get a conventional, loosely coupled, multi-tiered architecture. All modules are joined together by a parent Maven module, which only contains the parent POM with general definitions for all sub modules.
Especially myapp-service(.jar) and myapp-persistence(.jar) hold their own configurable (!) application context parts with the needed objects. Both jars must be deployable with the containing variable definitions, in other words the jars must not have concrete values for the variables.
myapp-service-context.xml declares a solrServer bean with the variable of the server URL:
<bean id="solrServer" class="org.apache.solr.client.solrj.impl.HttpSolrServer">
<constructor-arg value="${solr.serverUrl}" />
<property name="connectionTimeout" value="60000"/>
<property name="defaultMaxConnectionsPerHost" value="40"/>
<property name="maxTotalConnections" value="40"/>
</bean>
myapp-persistence-context.xml defines a dataSource with connection variables:
<bean id="dataSource" class="org.springframework.jdbc.datasource.DriverManagerDataSource">
<property name="driverClassName" value="${jdbc.driverClassName}" />
<property name="url" value="${jdbc.url}" />
<property name="username" value="${jdbc.username}" />
<property name="password" value="${jdbc.password}" />
</bean>
...
<bean id="sessionFactory" class="org.springframework.orm.hibernate3.annotation.AnnotationSessionFactoryBean">
<property name="dataSource" ref="dataSource" />
...
</bean>
myapp-web(.war) references myapp-service(.jar) and myapp-persistence(.jar). In myapp-servlet.xml it includes their application context parts and provides the property values for configuration of the declared beans by a property file. By context:property-placeholder Spring initializes all the variables with the concrete values when it creates the application context in memory.
<context:property-placeholder location="classpath*:myapp-configuration.properties" />
<import resource="classpath*:myapp-persistence-context.xml"/>
<import resource="classpath*:myapp-service-context.xml"/>
For the development profile the concrete myapp-configuration.properties may look like:
solr.serverUrl=http://localhost:8983/solr
jdbc.dialect=org.hibernate.dialect.HSQLDialect
jdbc.driverClassName=org.hsqldb.jdbcDriver
jdbc.url=jdbc:hsqldb:mem:myapp
jdbc.username=sa
jdbc.password=
This configuration is imo straight forward and works - without view. The problem arises when org.springframework.orm.hibernate3.support.OpenSessionInViewFilter comes into play.
Problem description
OpenSessionInViewFilter ensures that instances in the object graph which are not loaded within an open transaction during the controller processing can be lazily loaded, if the view tries to display these objects´ content (see [1]). As often described this filter is declared in the delpoyment descriptor web.xml (see [2]):
<filter>
<filter-name>OpenSessionInViewFilter</filter-name>
<filter-class>org.springframework.orm.hibernate3.support.OpenSessionInViewFilter</filter-class>
</filter>
<filter-mapping>
<filter-name>OpenSessionInViewFilter</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
If myapp-persistence-context.xml is included in myapp-servlet.xml like above so that context:property-placeholder works, OpenSessionInViewFilter does not find the necessary sessionFactory. The reason seems to be that Spring first processes web.xml and then myapp-servlet.xml, which imports myapp-persistence-context.xml. Unfourtunately I can´t proof this guess by a reference. Following exception is thrown:
GRAVE: Servlet.service() for servlet [myapp] in context with path [/myapp] threw exception
org.springframework.beans.factory.NoSuchBeanDefinitionException: No bean named 'sessionFactory' is defined
at org.springframework.beans.factory.support.DefaultListableBeanFactory.getBeanDefinition(DefaultListableBeanFactory.java:529)
at org.springframework.beans.factory.support.AbstractBeanFactory.getMergedLocalBeanDefinition(AbstractBeanFactory.java:1095)
at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:277)
at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:197)
at org.springframework.context.support.AbstractApplicationContext.getBean(AbstractApplicationContext.java:1097)
at org.springframework.orm.hibernate3.support.OpenSessionInViewFilter.lookupSessionFactory(OpenSessionInViewFilter.java:242)
at org.springframework.orm.hibernate3.support.OpenSessionInViewFilter.lookupSessionFactory(OpenSessionInViewFilter.java:227)
at org.springframework.orm.hibernate3.support.OpenSessionInViewFilter.doFilterInternal(OpenSessionInViewFilter.java:171)
at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:76)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:243)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210)
at org.springframework.web.filter.CharacterEncodingFilter.doFilterInternal(CharacterEncodingFilter.java:88)
at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:76)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:243)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:222)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:123)
at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:472)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:171)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:99)
at org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:936)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:118)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:407)
at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1004)
at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:589)
at org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.java:310)
at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:886)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:908)
at java.lang.Thread.run(Thread.java:662)
Different application context parts are usually included by the deployment descriptor with a ContextLoaderListener and not by myapp-servlet.xml:
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>
classpath*:myapp-service-context.xml,
classpath*:myapp-persistence-context.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>
With this configuration unfourtunately, Spring´ s context:property-placeholder mechanism seems not to work any more.
Objective and Question
Modules like myapp-persistence(.jar) and myapp-service(.jar) must be configurable at run-time with a property file by the referencing context, e.g. the application context of myapp-web(.war).
The question is: Is it possible to configure OpenSessionInViewFilter in Spring application context so that context:property-placeholder is still useable?
Or alternatively: How can variables in applicaton contexts be initialized by Spring at run-time, if application context parts are included in the deployment descriptor web.xml?
Fundamentally: Why is actually OpenSessionInViewFilter necessary to be configured, why Spring MVC does not transparently support view lazy loading out-of-the-box?
Anticipating Remarks
Property replacement at compile-time is not the point here. The profile dependent property file is already created with Maven Filtering.
Moving dataSource and solrServer declarations into myapp-servlet.xml as already proposed (see [3], [4]) is not an acceptable solution, because it destroyes modularity and independent testability of myapp-persistence(.jar) and myapp-service(.jar) - actually the spirit of dependency injection!
Talking to a colleague brought the solution: context:property-placeholder remains useable if I use Spring´s interceptor instead of the Servlet-API´s filter mechanism. I removed the reference of myapp-persistence-context.xml in contextConfigLocation and the OpenSessionInViewFilter from web.xml and declared an OpenSessionInViewInterceptor in myapp-persistence-context.xml:
<mvc:interceptors>
<bean id="openSessionInViewInterceptor" class="org.springframework.orm.hibernate3.support.OpenSessionInViewInterceptor">
<property name="sessionFactory" ref="sessionFactory" />
</bean>
</mvc:interceptors>
With myapp-persistence-context.xml in the classpath of myapp-persistence(.jar) and the import statement in myapp-servlet.xml as described above, Spring replaces all property variables with the values in myapp-configuration.properties at run-time as intended. Modularity is saved at its best! Will Keeling´s externalization of the property file completes the project setup.
See also the discussion Spring HandlerInterceptor vs Servlet Filters and the Spring doc.
You should certainly keep the sessionFactory and non-web related beans in the root application context as defined by the contextConfigLocation in the web.xml. Apart from the modularity aspect (as you mention), the OpenSessionInViewFilter needs it this way because it looks for the sessionFactory in the root web application context and it will error if it can't find it there - as you discovered. So your contextConfigLocation setup is the correct way to go.
PropertyPlaceholderConfigurer is a BeanFactoryPostProcessor which means it works within the context of the bean factory in which it is defined. In this case, it is defined in myapp-servlet.xml which means it will work within the web context but it won't resolve the placeholders in the root application context (where the dataSource and solrServer are defined).
My suggestion would be to move the <context:property-placeholder> from the web to the root application context - but parameterize the location allowing this to be set by the enclosing app. For example, you could add this to your myapp-service-context.xml
<context:property-placeholder location="${props.file}"/>
And then you can leave it to the myapp-web.war (or whatever the parent app happens to be) to set the location of the file. For example, this could be done as a system property:
-Dprops.file=file:C:/myapp-configuration.properties

Invalid Oracle URL specified: OracleDataSource.makeURL in Arquillian ITest

I persist with every error I get thrown and mostly always work out the solution. I find a good walk helps. But this one has me stumped, I've been staring at this same error all day. Like Ticcie in Invalid Oracle URL specified: OracleDataSource.makeURL suggests, the error message does nothing to help understand what is wrong.
SEVERE: Exception during lifecycle processing
org.glassfish.deployment.common.DeploymentException: Exception [EclipseLink-4002] (Eclipse Persistence Services - 2.5.0.v20130507-3faac2b): org.eclipse.persistence.exceptions.DatabaseException
Internal Exception: java.sql.SQLException: Error in allocating a connection. Cause: Connection could not be allocated because: Invalid Oracle URL specified: OracleDataSource.makeURL
Error Code: 0
at org.eclipse.persistence.internal.jpa.EntityManagerSetupImpl.deploy(EntityManagerSetupImpl.java:762)
at org.eclipse.persistence.internal.jpa.EntityManagerFactoryDelegate.getAbstractSession(EntityManagerFactoryDelegate.java:204)
I am doing Arquillian Integration Testing for a Java EE 7 EAR application. Its been going well using JPA and the DerbyDb but I now need to test Native Oracle DB (11g) SQL. So I've setup a new testing project to connect to an OracleDB using EclipseLink.
I CAN connect to the database through the Eclipse IDE DataSource explorer and ping it no problems.
I DO connect to a sister Oracle database in Glassfish standalone and ping it no problems.
But the Arquillian Test cannot connect to it with the above ambiguous error. It would be nice if the error said what exactly is the problem.
I use exactly the same URL as I have with the Eclipse IDE DataSource explorer:
jdbc:oracle:thin:#marina.work.com:1521:orcl
The Arquillian setup is the same as I did for DerbyDb (pretty-much same as http://arquillian.org/guides/testing_java_persistence/) with these variations for OracleDB:
src/main/resources-glassfish-embedded/sun-resources.xml
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE resources PUBLIC "-//GlassFish.org//DTD GlassFish Application Server 3.1 Resource Definitions//EN" "http://glassfish.org/dtds/glassfish-resources_1_5.dtd">
<resources>
<jdbc-resource pool-name="ArquillianOraclePool" jndi-name="jdbc/arquillian" />
<jdbc-connection-pool name="ArquillianOraclePool" res-type="javax.sql.DataSource" datasource-classname="oracle.jdbc.pool.OracleDataSource"
is-isolation-level-guaranteed="false" >
</jdbc-connection-pool>
</resources>
src/main/resources-glassfish-embedded/test-persistence.xml
<?xml version="1.0" encoding="UTF-8"?>
<persistence version="2.0" xmlns="http://java.sun.com/xml/ns/persistence" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="
http://java.sun.com/xml/ns/persistence
http://java.sun.com/xml/ns/persistence/persistence_2_0.xsd">
<persistence-unit name="esaarch01-pu" transaction-type="JTA">
<provider>org.eclipse.persistence.jpa.PersistenceProvider</provider>
<jta-data-source>jdbc/arquillian</jta-data-source>
<jar-file>test.jar</jar-file>
<exclude-unlisted-classes>false</exclude-unlisted-classes>
<properties>
<property name="javax.persistence.jdbc.Url" value="jdbc:oracle:thin:#marina.work.com:1521:orcl" />
<property name="javax.persistence.jdbc.Password" value="demo" />
<property name="javax.persistence.jdbc.User" value="test" />
<property name="javax.persistence.jdbc.driver" value="oracle.jdbc.OracleDriver" /> <!-- driver. -->
<property name="javax.persistence.jdbc.platform" value="org.eclipse.persistence.platform.database.oracle.OraclePlatform" />
<property name="eclipselink.ddl-generation" value="drop-and-create-tables" />
<property name="eclipselink.logging.level" value="FINE" />
<property name="eclipselink.logging.level.sql" value="FINE" />
</properties>
</persistence-unit>
</persistence>
I've introduced XML well-formedness errors such as text in the properties element and receive the following error. This shows that this file is being picked up for the correct purposes:
java.io.IOException: org.xml.sax.SAXParseException; lineNumber: 21; columnNumber: 16; Deployment descriptor file META-INF/persistence.xml in archive [test.jar]. cvc-complex-type.2.3: Element 'properties' cannot have character [children], because the ...
I've tried different property names but none change the error message. Which makes me think that the URL property isn't being picked up at all.
I've tried different variations of the URL (with matching mods for name and password):
javax.persistence.jdbc.url URL Url (three variations)
eclipselink.jdbc.url URL Url (three variations)
No variation works. Same error.
It would be really nice if the exception can be more specific about what it can and cannot find.
My question is, can anyone tell me the solution or suggest what's wrong or something I can try and work out what is going wrong?
UPDATE
I've posted this question on the Oracle forums and included the entire stack trace and the sample minimal code plus some instructions. If anyone is keen to look at it I'd be grateful.
https://forums.oracle.com/message/11152777#11152777
driver type is not provided, for my case, I used "thin" xaProperties.driverType="thin", please find similar config for your case.

External properties loader with Tomcat server

I am trying to deploy a spring mvc webapp into a tomcat server. I have been testing locally using the maven-jetty-plugin. In my spring configuration I am using a properties placeholder, and pulling my properties from an external file:
<context:property-placeholder ignore-resource-not-found="true" ignore-unresolvable="true"/>
<bean id="modelPropertyPlaceholder" class="org.springframework.web.context.support.ServletContextPropertyPlaceholderConfigurer">
<property name="systemPropertiesModeName" value="SYSTEM_PROPERTIES_MODE_OVERRIDE"/>
<property name="searchContextAttributes" value="true"/>
<property name="contextOverride" value="true"/>
<property name="ignoreResourceNotFound" value="true"/>
<property name="ignoreUnresolvablePlaceholders" value="true"/>
<property name="locations">
<list>
<value>classpath:default.model.properties</value>
<value>file:/etc/app/app.properties</value>
<value>${config}</value>
</list>
</property>
</bean>
This worked with my jetty plugin...however when I deploy the WAR file to the tomcat server I receive the following error:
org.apache.commons.dbcp.SQLNestedException: Cannot create JDBC driver of class '' for connect URL 'null'
In my external properties file I have the driver class and connect url defined. as so:
jndi.jpa.rms.datasource=jdbc/testDS
rms.db.driver=com.mysql.jdbc.Driver
rms.db.url=jdbc:mysql://testdatabaseurl:3306/test
rms.db.user=sa
rms.db.password=asfdas
rms.db.checkconnsql=select 1
rms.hibernate.generateddl=false
rms.hibernate.showsql=true
rms.hibernate.dbdialect=org.hibernate.dialect.MySQLDialect
Update:
It seems that tomcat does pickup the external properties file:
14:23:09.803 [main] DEBUG o.s.b.f.s.DefaultListableBeanFactory - Finished creating instance of bean 'modelPropertyPlaceholder'
14:23:09.810 [main] INFO o.s.w.c.s.ServletContextPropertyPlaceholderConfigurer - Loading properties file from class path resource [default.model.properties]
14:23:09.810 [main] INFO o.s.w.c.s.ServletContextPropertyPlaceholderConfigurer - Loading properties file from URL [file:/etc/app/app.properties]
14:23:09.810 [main] INFO o.s.w.c.s.ServletContextPropertyPlaceholderConfigurer - Loading properties file from ServletContext resource [/${config}]
14:23:09.811 [main] WARN o.s.w.c.s.ServletContextPropertyPlaceholderConfigurer - Could not load properties from ServletContext resource [/${config}]: Could not open ServletContext resource [/${config}]
I'm not sure why tomcat isn't picking up the connection url and driver.
Is this a tomcat issue or am I missing something? Thanks
It's not a Tomcat issue, you must have made some minor mistake and properties are not loaded.
Are properties files located in proper place on your Tomcat environment?
Are you sure that in those properties files you have not left some keys blank?
If both answers to that questions are true, try changing your config with following:
<context:property-placeholder location="ADD_PATH_TO_YOUR_FILES SEPARATED_WITH_SPACES"/>
I guess that you are mixing here two property placeholders, one 'regular' and the other - bounded to servlet context. I can bet that somehow they get overlapped and one of them is getting silently ignored.
I would just stick to property-placeholder.
Old question, but...
Judging from the log output, it appears that Spring has not resolved your ${config} reference, or else this would have been substituted into the path given in the last log message:
Could not load properties from ServletContext resource [/${config}]: Could not open ServletContext resource [/${config}]
Here's a case I just encountered where it resolved ${catalina.home}/conf/myprops.properties correctly but was unable to load the referenced file:
Could not load properties from ServletContext resource [/D:/somepath/apache-tomcat/conf/myprops.properties]: Could not open ServletContext resource [/D:/somepath/apache-tomcat/conf/myprops.properties]
I tracked down the error in my case - I needed to prefix the external file reference with 'file:'. That is, it should have been file:${catalina.home}/conf/myprops.properties
(It is possible the Spring version difference may have impacted on the log output for you though also, and that it did resolve the reference but just did not show this in the output. For reference, I'm using Spring 4.1.6 at present).

spring 3.0.5 how to define interceptor with configurable URI path

I am using spring 3.0.5 MVC and trying to defined LoginInterceptor for specified path /fx. I looked up and found the way to use is:
<mvc:interceptors>
<!-- Changes the locale when a 'locale' request parameter is sent; e.g. /?locale=de -->
<bean class="org.springframework.web.servlet.i18n.LocaleChangeInterceptor" />
<mvc:interceptor>
<mapping path="/fx"/>
<bean class="com.fxiapi.auth.LoginInterceptor" />
</mvc:interceptor>
</mvc:interceptors>
I want to use this for any page other than Login page for certain URI. Is their a way to ignore login page URI. Also, using this was I am getting following exception:
2011-02-07 11:04:22,756 ERROR http-0.0.0.0-8680-1 Context initialization failed
org.springframework.beans.factory.xml.XmlBeanDefinitionStoreException: Line 31 in XML document from ServletContext resource [/WEB-INF/spring/appServlet/servlet-context.xml] is invalid; nested exception is org.xml.sax.SAXParseException: cvc-complex-type.2.4.a: Invalid content was found starting with element 'mapping'. One of '{"http://www.springframework.org/schema/mvc":mapping}' is expected.
at org.springframework.beans.factory.xml.XmlBeanDefinitionReader.doLoadBeanDefinitions(XmlBeanDefinitionReader.java:396)
Can someone please help? Whats the alternate if I cant use tag?
The error message tells you what's wrong - you need the namespace prefix on the <mapping> element also:
<mvc:interceptor>
<mvc:mapping path="/fx"/>
...
</mvc:interceptor>

Resources