Spring #Transactional configuring xml - java

The rollback in my transaction doesn't work (Spring 3.1). I tried to edit my configuration xml file, like here but without result.
Here my xml file:
<beans xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:mvc="http://www.springframework.org/schema/mvc"
xmlns="http://www.springframework.org/schema/beans"
xmlns:jee="http://www.springframework.org/schema/jee"
xmlns:aop= "http://www.springframework.org/schema/aop"
xmlns:tx= "http://www.springframework.org/schema/tx"
xmlns:jpa="http://www.springframework.org/schema/data/jpa"
xsi:schemaLocation="
http://www.springframework.org/schema/mvc
http://www.springframework.org/schema/mvc/spring-mvc.xsd
http://www.springframework.org/schema/jee
http://www.springframework.org/schema/jee/spring-jee-3.1.xsd
http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans.xsd
http://www.springframework.org/schema/aop
http://www.springframework.org/schema/aop/spring-aop-2.0.xsd
http://www.springframework.org/schema/tx
http://www.springframework.org/schema/tx/spring-tx-2.0.xsd
http://www.springframework.org/schema/data/jpa http://www.springframework.org/schema/data/jpa/spring-jpa.xsd
">
<jee:jndi-lookup id="dataSourceUsrAppe1" jndi-name="jdbc/ZhabDS"/>
<bean id="utentiDAO" class="it.dao.UtentiDAO">
<property name="dataSourceUsrAppe1">
<ref bean="dataSourceUsrAppe1"/>
</property>
</bean>
<!-- doesn't work with this:
<tx:annotation-driven transaction-manager="txManager"/>
<property name="dataSourceUsrAppe1">
<ref bean="dataSourceUsrAppe1"/>
</property>
</bean>
</beans>
-->
</beans>
Should I add a transaction manager here?
Here's my service:
#Service
public class UtentiService {
#Autowired
private UtentiDAO utentiDAO;
#Transactional(rollbackFor={Exception.class}, propagation=Propagation.REQUIRED)
public boolean createUser(Zhabuten user) throws Exception
{
long idPrincipale;
idPrincipale = utentiDAO.insert(user, utentiDAO.query1);
idPrincipale = utentiDAO.insert(user, utentiDAO.query2);
if (idPrincipale!=0) throw new java.lang.Exception();
idPrincipale = utentiDAO.insert(user, utentiDAO.query3);
return false;
}
}
The exception is correctly thrown, it's catched from the controller and the database is not rollbacked.
Do I missing any configuration in the xml?

Use the following xml configuration.
<!-- Enable Annotation based Declarative Transaction Management -->
<tx:annotation-driven proxy-target-class="true"
transaction-manager="transactionManager" />
<!-- Creating TransactionManager Bean, since JDBC we are creating of type
DataSourceTransactionManager -->
<bean id="transactionManager"
class="org.springframework.jdbc.datasource.DataSourceTransactionManager">
<property name="dataSource" ref="dataSourceUsrAppe1" />
</bean>

Related

Spring templateResolver configure

I have problem with correct configure templateResolver. When i try to get default page, its work fine. When i try go to the page with /someAddress i get
template might not exist or might not be accessible by any of the configured Template Resolvers
dispatcher-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/mvc
http://www.springframework.org/schema/mvc/spring-mvc.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context.xsd">
<mvc:annotation-driven/>
<context:component-scan base-package="com.javapointers.controllers"/>
<bean id="templateResolver"
class="org.thymeleaf.templateresolver.ServletContextTemplateResolver">
<property name="prefix" value="/WEB-INF/pages/"/>
<property name="suffix" value=".html"/>
<property name="templateMode" value="HTML5"/>
</bean>
<bean id="templateEngine" class="org.thymeleaf.spring4.SpringTemplateEngine">
<property name="templateResolver" ref="templateResolver"/>
</bean>
<mvc:resources mapping="/resources/**" location="/WEB-INF/resources/"/>
HomeController
#Controller
public class HomeController {
#RequestMapping(value="/", method = RequestMethod.GET)
public String viewHome(){
return "test";
}
#RequestMapping(value="/login", method = RequestMethod.GET)
public String login(){
return "login";
}
Does anyone know the correct configure?
I resolved the problem. In my app was another beans configuration in java class.

Spring #Autowired comes as null

I have #Component, A, which AutoWires a class which contains simple configurations for class A. I've created a bin for configuration file. But for some reason it comes as null. Could you please help me to find out the problem?
#Component
public class SearchEngineDriver {
#Autowired(required = true)
private EngineContext context;
public SearchEngineDriver(){
String clusterName = context.getClusterName();
}
}
public class EngineContext {
private String clusterName;
public EngineContext(String clusterName){
this.clusterName = clusterName;
}
public String getClusterName(){
return this.clusterName;
}
}
3rd class.
#Autowired
private SearchEngineDriver searchEngineDriver;
mvc-dispatcher-servlet.xml
<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">
<context:component-scan base-package="org.electronsoftware" />
<mvc:annotation-driven/>
<mvc:resources mapping="/resources/**" location="/resources/" />
<import resource="classpath*:/application-context.xml"/>
<bean
class="org.springframework.web.servlet.view.InternalResourceViewResolver">
<property name="prefix">
<value>/</value>
</property>
<property name="suffix">
<value>.jsp</value>
</property>
</bean>
</beans>
application-context.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"
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-3.2.xsd">
<context:property-placeholder location="classpath:application.properties"/>
<bean id="searchEngineContext" class="org.electronsoftware.KGB.search.context.EngineContext" >
<constructor-arg value="${kgb.search.engine.clustername}"/>
</bean>
</beans>
You are accessing the autowired field from the constructor. At the time the constructor runs, Spring has not yet got the chance to initialize the field. Instead use a #PostConstruct method to perform logic which depends on the autowired value.

PersistenceUnitInfo [appName] has transactionType JTA, but does not have a jtaDataSource defined

I am new to WebLogic and fairly new to Hibernate / Spring applications, as my primary language is C# and my primary servers have always been Windows Servers, so please forgive any simple errors I may have.
I am having trouble deploying to our WebLogic 10.3.4 server. It works locally on my WebLogic instance, but not on the remote server.
I am using Hibernate 4.2.8 for persistence and Spring MVC 4.0 for my web application framework. The error I am receiving is:
Failed to load webapp: 'ncms2_May20.war'
Message icon - Error Substituted for missing class Exception [EclipseLink-28010] (Eclipse Persistence Services - 2.1.2.v20101206-r8635) - org.eclipse.persistence.exceptions.EntityManagerSetupException Exception Description: PersistenceUnitInfo ncms2 has transactionType JTA, but does not have a jtaDataSource defined.
I am using a Spring annotation based Hibernate configuration file.
package mil.navy.navsupbsc.utilities;
import java.util.Properties;
import javax.sql.DataSource;
import com.app.AuditInterceptor;
import org.hibernate.SessionFactory;
import org.hibernate.dialect.Oracle10gDialect;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.jdbc.datasource.DriverManagerDataSource;
import org.springframework.orm.hibernate4.HibernateTransactionManager;
import org.springframework.orm.hibernate4.LocalSessionFactoryBean;
import org.springframework.orm.hibernate4.LocalSessionFactoryBuilder;
#Configuration
public class HibernateConfiguration {
#Value("#{dataSource}")
private DataSource dataSource;
#Bean
public LocalSessionFactoryBean sessionFactoryBean() {
Properties props = new Properties();
props.put("hibernate.dialect", Oracle10gDialect.class.getName());
props.put("hibernate.format_sql", "true");
props.put("hibernate.hbm2ddl.auto", "update");
props.put("hibernate.show_sql", "true");
props.put("hibernate.format_sql", "true");
props.put("hibernate.use_sql_comments", "true");
LocalSessionFactoryBean bean = new LocalSessionFactoryBean();
bean.setEntityInterceptor(new AuditInterceptor());
bean.setPackagesToScan(new String[] { "com.app.entity" });
bean.setHibernateProperties(props);
bean.setDataSource(this.dataSource);
return bean;
}
#Bean
public HibernateTransactionManager transactionManager() {
return new HibernateTransactionManager(sessionFactoryBean().getObject());
}
}
My Spring 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:aop="http://www.springframework.org/schema/aop"
xmlns:context="http://www.springframework.org/schema/context"
xmlns:jee="http://www.springframework.org/schema/jee" xmlns:lang="http://www.springframework.org/schema/lang"
xmlns:p="http://www.springframework.org/schema/p" xmlns:tx="http://www.springframework.org/schema/tx"
xmlns:util="http://www.springframework.org/schema/util" xmlns:c="http://www.springframework.org/schema/c"
xmlns:cache="http://www.springframework.org/schema/cache" xmlns:jdbc="http://www.springframework.org/schema/jdbc"
xmlns:task="http://www.springframework.org/schema/task" xmlns:mvc="http://www.springframework.org/schema/mvc"
xsi:schemaLocation="http://www.springframework.org/schema/jdbc http://www.springframework.org/schema/jdbc/spring-jdbc-4.0.xsd
http://www.springframework.org/schema/lang http://www.springframework.org/schema/lang/spring-lang.xsd
http://www.springframework.org/schema/jee http://www.springframework.org/schema/jee/spring-jee.xsd
http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop.xsd
http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc-4.0.xsd
http://www.springframework.org/schema/task http://www.springframework.org/schema/task/spring-task-4.0.xsd
http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
http://www.springframework.org/schema/util http://www.springframework.org/schema/util/spring-util.xsd
http://www.springframework.org/schema/cache http://www.springframework.org/schema/cache/spring-cache-4.0.xsd
http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx.xsd
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd">
<bean id="messageSource"
class="org.springframework.context.support.ReloadableResourceBundleMessageSource">
<property name="basename" value="classpath:messages" />
<property name="defaultEncoding" value="UTF-8" />
</bean>
<bean id="propertyConfigurer"
class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer"
p:location="/WEB-INF/jdbc.properties" />
<bean id="dataSource"
class="org.springframework.jdbc.datasource.DriverManagerDataSource"
p:driverClassName="${jdbc.driverClassName}" p:url="${jdbc.databaseurl}"
p:username="${jdbc.username}" p:password="${jdbc.password}" />
<mvc:annotation-driven />
<tx:annotation-driven transaction-manager="transactionManager" />
<mvc:resources mapping="/resources/**" location="/resources/" />
<context:component-scan base-package="com.app" />
<bean id="viewResolver"
class="org.springframework.web.servlet.view.UrlBasedViewResolver">
<property name="viewClass">
<value>
org.springframework.web.servlet.view.tiles2.TilesView
</value>
</property>
</bean>
<bean id="tilesConfigurer"
class="org.springframework.web.servlet.view.tiles2.TilesConfigurer">
<property name="definitions">
<list>
<value>/WEB-INF/tiles.xml</value>
</list>
</property>
</bean>
</beans>
Could any of you assist me in getting this to work? I appreciate any and all help. Thank you!
Update
I did the following to switch it to JTA:
added a JtaTransactionManager in the Hibernate java configuration file rather than using the HibernateTransactionManager.
set the JtaTransactionManager property in the LocalSessionFactoryBean
added a jdni lookup in the spring-servlet file
added a resource reference in both the web.xml and weblogic.xml files
removed the data source in spring-servlet and removed the reference to it in the hibernate java configuration file
created a data source on the server
Still not working 100% though. Will keep this updated.
UPDATE: Here's a helpful resource that I've been using (http://spring.io/blog/2011/08/15/configuring-spring-and-jta-without-full-java-ee/)
You haven't posted your persistence.xml JPA configuration file but it may contain something like:
<persistence-unit name="..." transaction-type="JTA">
<jta-data-source>java:/DefaultDS</jta-data-source>
When deploying on application servers you should benefit from their own JTA data sources and transaction manager support, so locating the jtaDataSource through JNDI should be your first option.
Your data source is configured with Spring:
org.springframework.jdbc.datasource.DriverManagerDataSource
and that's not really a production ready data source implementation.
So, try to configure your Spring application context to make use of the WebLogic transaction management support.
I used the information given in the answer by #Vlad Mihalcea to improve my code; however, it was not the reason it was not working. One of #Vlad's comments that suggested looking for a persistence.xml file in the META-INF folder clued me into the answer.
Even though I was using the Spring configuration file for Hibernate, I had an old persistence.xml file under the META-INF folder. I wasn't using it, but WebLogic was picking it up automatically. Since I wasn't using it, I didn't have a data source specified in the persistence.xml file. WebLogic automatically assumes any persistence unit is JTA if not specified as RESOURCE LOCAL. I deleted that persistence.xml file, and it worked.
That said, I also fixed up my code to use the JTA data source as #Vlad Mihalcea suggested. I moved all my configuration code to the Spring-servlet.xml file to simplify the configuration. I'm sure it could be translated into the programmatic Spring configuration without too much trouble.
In the meantime, here is a working JTA transaction based Spring / Hibernate configuration file.
<?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:aop="http://www.springframework.org/schema/aop"
xmlns:context="http://www.springframework.org/schema/context"
xmlns:jee="http://www.springframework.org/schema/jee" xmlns:lang="http://www.springframework.org/schema/lang"
xmlns:p="http://www.springframework.org/schema/p" xmlns:tx="http://www.springframework.org/schema/tx"
xmlns:util="http://www.springframework.org/schema/util" xmlns:c="http://www.springframework.org/schema/c"
xmlns:cache="http://www.springframework.org/schema/cache" xmlns:jdbc="http://www.springframework.org/schema/jdbc"
xmlns:task="http://www.springframework.org/schema/task" xmlns:mvc="http://www.springframework.org/schema/mvc"
xsi:schemaLocation="http://www.springframework.org/schema/jdbc http://www.springframework.org/schema/jdbc/spring-jdbc-4.0.xsd
http://www.springframework.org/schema/lang http://www.springframework.org/schema/lang/spring-lang.xsd
http://www.springframework.org/schema/jee http://www.springframework.org/schema/jee/spring-jee.xsd
http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop.xsd
http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc-4.0.xsd
http://www.springframework.org/schema/task http://www.springframework.org/schema/task/spring-task-4.0.xsd
http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
http://www.springframework.org/schema/util http://www.springframework.org/schema/util/spring-util.xsd
http://www.springframework.org/schema/cache http://www.springframework.org/schema/cache/spring-cache-4.0.xsd
http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx.xsd
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd">
<bean id="messageSource"
class="org.springframework.context.support.ReloadableResourceBundleMessageSource">
<property name="basename" value="classpath:messages" />
<property name="defaultEncoding" value="UTF-8" />
</bean>
<bean id="sessionFactory"
class="org.springframework.orm.hibernate4.LocalSessionFactoryBean">
<property name="packagesToScan" value="mil.navy.navsupbsc.entity" />
<property name="dataSource" ref="NCS"/>
<property name="jtaTransactionManager" ref="transactionManager" />
<property name="hibernateProperties">
<props>
<prop key="hibernate.transaction.jta.platform">org.hibernate.service.jta.platform.internal.WeblogicJtaPlatform
</prop>
<prop key="hibernate.hbm2ddl.auto">update</prop>
<prop key="hibernate.dialect">org.hibernate.dialect.Oracle10gDialect</prop>
<prop key="hibernate.driverClassName">oracle.jdbc.OracleDriver</prop>
<prop key="hibernate.show_sql">true</prop>
<prop key="hibernate.format_sql">true</prop>
<prop key="hibernate.use_sql_comments">true</prop>
</props>
</property>
</bean>
<mvc:annotation-driven />
<mvc:resources mapping="/resources/**" location="/resources/" />
<context:component-scan base-package="mil.navy.navsupbsc" />
<tx:annotation-driven transaction-manager="transactionManager" />
<jee:jndi-lookup id="NCS" jndi-name="NCS" resource-ref="false">
</jee:jndi-lookup>
<tx:jta-transaction-manager id="transactionManager" />
<bean id="viewResolver"
class="org.springframework.web.servlet.view.UrlBasedViewResolver">
<property name="viewClass">
<value>
org.springframework.web.servlet.view.tiles2.TilesView
</value>
</property>
</bean>
<bean id="tilesConfigurer"
class="org.springframework.web.servlet.view.tiles2.TilesConfigurer">
<property name="definitions">
<list>
<value>/WEB-INF/tiles.xml</value>
</list>
</property>
</bean>
</beans>
Note that I also needed to add references in the web.xml and WebLogic.xml files to the JNDI data source I created on the web server (called NCS in my application).

Cannot resolve property `paramName` in Spring MVC

I need to set Spring MVC interseptors to catch url parameter language and accordingly get data from .properties file. Getting error Cannot resolve propertyparamName when configuring context in servlet-config.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"
xmlns:p="http://www.springframework.org/schema/p"
xsi:schemaLocation="http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc-3.2.xsd
http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.2.xsd">
<mvc:annotation-driven/>
<mvc:resources mapping="/pdfs" location="pdfs"/>
<context:component-scan base-package="com.ttu.cs.controller"/>
<bean id="messageSource" class="org.springframework.context.support.ResourceBundleMessageSource" p:basename="messages" />
<bean class="org.springframework.web.servlet.view.InternalResourceViewResolver"
p:prefix="/WEB-INF/jsp/" p:suffix=".jsp" />
<bean id="LocaleResolver" class="org.springframework.web.servlet.i18n.SessionLocaleResolver" p:defaultLocale="en"/>
<!-- Declare the Interceptor -->
<mvc:interceptors>
<bean class="org.springframework.web.servlet.i18n.SessionLocaleResolver">
<property name="paramName" value="language"/>
</bean>
</mvc:interceptors>
</beans>
I think you meant to use org.springframework.web.servlet.i18n.LocaleChangeInterceptor rather than SessionLocaleResolver.
<bean class="org.springframework.web.servlet.i18n.LocaleChangeInterceptor">
<property name="paramName" value="language"/>
</bean>
This class is a HandlerInterceptor and does have a paramName property.
SessionLocaleResolver, on the other hand, is not.
Not sure what you expect but SessionLocaleResolver doesn't have such a param. Maybe you meant locale?

no declaration can be found for element 'mvc:annotation-driven'

I have the requirement of returning JSON/XML data from my controller.From what i found,I needed #ResponseBody in my method and for that I need <mvc:annotation-driven> enabled. I have tried all sorts of RnD but am still stuck! :(
Apparently my problem lies in my servlet.xml file (the schema isnt getting validated!)
I am using Spring 3.1.1 & have explicitly put in spring-mvc-3.1.1.jar in my classpath.
Here's my servlet-context file sample-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/tx http://www.springframework.org/schema/tx/spring-tx.xsd
http://www.springframework.org/schema/mvc-3.1 http://www.springframework.org/schema/mvc/spring-mvc-3.1.xsd
http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd">
<context:component-scan base-package="com.sample.controller"/>
<mvc:annotation-driven/>
<!--Use JAXB OXM marshaller to marshall/unmarshall following class-->
<bean class="org.springframework.web.servlet.view.BeanNameViewResolver" />
<bean id="xmlViewer"
class="org.springframework.web.servlet.view.xml.MarshallingView">
<constructor-arg>
<bean class="org.springframework.oxm.jaxb.Jaxb2Marshaller">
<property name="classesToBeBound">
<list>
<value>com.sample.model.SampleClass</value>
</list>
</property>
</bean>
</constructor-arg>
</bean>
<bean class="org.springframework.web.servlet.view.ContentNegotiatingViewResolver">
<property name="viewResolvers">
<list>
<bean class="org.springframework.web.servlet.view.UrlBasedViewResolver">
<property name="viewClass" value="org.springframework.web.servlet.view.JstlView"/>
<property name="prefix" value="/WEB-INF/jsp/"/>
<property name="suffix" value=".jsp"/>
</bean>
</list>
</property>
</bean>
My controller class looks like this :
#Controller
public class XmlController {
#RequestMapping(value="/getXml",method = RequestMethod.POST)
public #ResponseBody AssociateDetail getXml(){
System.out.println("inside xml controller.....");
AssociateDetail assoBean=null;
try{
AssociateService add=new AssociateService();
assoBean=add.selectAssociateBean();
}catch(Exception e){
e.printStackTrace();
}
return assoBean;
}
}
Now the problem is <mvc:annotation-driven /> gives error:
cvc-complex-type.2.4.c: The matching wildcard is strict, but no declaration can be found for element 'mvc:annotation-driven'.
And I have tried all the workarounds suggested on this site and beyond. Have updated my schema namespaces, using Spring 3.1.1 and #ResponseBody.
As the error suggests there's something wrong with the schema declaration. You do not have the xsd s declared.
Use this instead.
<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:tx="http://www.springframework.org/schema/tx"
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.1.xsd
http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-3.1.xsd
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">
Add the following schemas to your schemaLocation declaration at the top:
http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc-4.2.xsd

Categories