Configuring multiple controllers in dispatcher servlet - spring-mvc

I am new to spring-hibernate integration.
I am trying to enter data into database through jsp form, and I am getting a null pointer exception when the object is trying to persit.
I checked if the object is receiving values, and it does.
The reason I feel is because the dispatcher servelet is not allowing me to pass the value through.
Bellow is my dispatcher-servlet.
If any one can me show me the way to configure multiple controllers in dispatcher servelet it would be great.
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:mvc="http://www.springframework.org/schema/mvc"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:util="http://www.springframework.org/schema/util"
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
http://www.springframework.org/schema/util http://www.springframework.org/schema/util/spring-util-3.0.xsd">
<!-- maps request URLs to Controller names -->
<!-- <bean class="org.springframework.web.servlet.mvc.support.ControllerClassNameHandlerMapping"/> -->
<!-- bean class="com.skopic.web.controller.UserController" /-->
<bean name="/index/*.htm" class="com.skopic.web.controller.IndexController" >
<!-- <property name="UserDAO" ref="myUserDAO" /> -->
</bean>
<bean id="jspViewResolver" class="org.springframework.web.servlet.view.InternalResourceViewResolver">
<property name="viewClass" value="org.springframework.web.servlet.view.JstlView"/>
<property name="prefix" value="/jsp/"/>
<property name="suffix" value=".jsp"/>
</bean>
<bean id="propertyPlaceholderConfigurer" class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
<property name="locations">
<list>
<value>classpath:skopicportal.${SKAPP_ENV}.properties</value>
</list>
</property>
</bean>
<bean id="myDataSource" class="org.apache.commons.dbcp.BasicDataSource" destroy-method="close">
<property name="driverClassName" value="com.mysql.jdbc.Driver"/>
<property name="url" value="jdbc:mysql://localhost:3306/testdb"/>
<property name="username" value="root"/>
<property name="password" value="root"/>
</bean>
<!-- <bean id="mySessionFactory" class="org.springframework.orm.hibernate3.annotation.AnnotationSessionFactoryBean">
<property name="dataSource" ref="myDataSource" />
<property name="annotatedClasses">
<list>
<value>com.skopic.web.controller.Tenant</value>
</list>
</property>
<property name="hibernateProperties">
<props>
<prop key="hibernate.dialect">org.hibernate.dialect.MySQLDialect</prop>
<prop key="hibernate.show_sql">true</prop>
<prop key="hibernate.hbm2ddl.auto">create</prop>
</props>
</property>
</bean>
<bean id="myTenantDAO" class="com.skopic.web.controller.TenantDAOImpl">
<property name="sessionFactory" ref="mySessionFactory"/>
</bean> -->
<!-- User bean -->
<bean id="mySessionFactory" class="org.springframework.orm.hibernate3.annotation.AnnotationSessionFactoryBean">
<property name="dataSource" ref="myDataSource" />
<property name="annotatedClasses">
<list>
<value>com.skopic.web.controller.User</value>
</list>
</property>
<property name="hibernateProperties">
<props>
<prop key="hibernate.dialect">org.hibernate.dialect.MySQLDialect</prop>
<prop key="hibernate.show_sql">true</prop>
<prop key="hibernate.hbm2ddl.auto">create</prop>
</props>
</property>
</bean>
<bean id="myUserDAO" class="com.skopic.web.controller.UserDAOImpl">
<property name="sessionFactory" ref="mySessionFactory"/>
</bean>
<bean name="/user/*.htm" class="com.skopic.web.controller.UserController" >
<property name="UserDAO" ref="myUserDAO" />
</bean>
<!-- <bean id="multipartResolver" class="org.springframework.web.multipart.commons.CommonsMultipartResolver"/> -->
<mvc:annotation-driven/>
<context:component-scan base-package="com.skopic.service"/>
<context:component-scan base-package="com.skopic.web.controller"/>
</beans>

Related

How to enable #RequiresPermissions in Spring MVC project?

Having spent days trying to get my head around AOP, I have no option than to lay out my code and hope the good guys on the internet will help me.
My dispatcher-servlet.xml:
<?xml version='1.0' encoding='UTF-8' ?>
<!-- was: <?xml version=".0" encoding="UTF-8"?> -->
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:p="http://www.springframework.org/schema/p"
xmlns:aop="http://www.springframework.org/schema/aop"
xmlns:tx="http://www.springframework.org/schema/tx"
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/aop http://www.springframework.org/schema/aop/spring-aop.xsd
http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx.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">
<context:component-scan base-package="com.company.project"/>
<mvc:annotation-driven/>
<mvc:resources mapping="/resources/**" location="/WEB-INF/resources/, file:${catalina.home}/project/resources/" />
<bean id="urlMapping" class="org.springframework.web.servlet.handler.SimpleUrlHandlerMapping">
<property name="mappings">
<props>
<prop key="index.htm">indexController</prop>
</props>
</property>
</bean>
<bean id="viewResolver"
class="org.springframework.web.servlet.view.InternalResourceViewResolver"
p:prefix="/WEB-INF/jsp/"
p:suffix=".jsp" />
<!--
The index controller.
-->
<bean name="indexController"
class="org.springframework.web.servlet.mvc.ParameterizableViewController"
p:viewName="index" />
</beans>
applicationContext.xml:
<?xml version='1.0' encoding='UTF-8' ?>
<!-- was: <?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:tx="http://www.springframework.org/schema/tx"
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/aop http://www.springframework.org/schema/aop/spring-aop.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">
<aop:aspectj-autoproxy proxy-target-class="true"/>
<context:component-scan base-package="com.company.project"/>
<!-- Transaction Management -->
<tx:annotation-driven transaction-manager="transactionManager" proxy-target-class="true"/>
<bean id="propertyConfigurer" class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
<property name="locations">
<list>
<value>/WEB-INF/jdbc.properties</value>
<value>/WEB-INF/c3p0.properties</value>
<value>/WEB-INF/application.properties</value>
</list>
</property>
</bean>
<!-- With c3p0-->
<bean id="dataSource" class="com.mchange.v2.c3p0.ComboPooledDataSource" destroy-method="close">
<property name="driverClass" value="${jdbc.driverClassName}"/>
<property name="jdbcUrl" value="${jdbc.url}"/>
<property name="user" value="${jdbc.username}" />
<property name="password" value="${jdbc.password}" />
</bean>
<bean id="sessionFactory" class="org.springframework.orm.hibernate5.LocalSessionFactoryBean">
<property name="dataSource" ref="dataSource"/>
<property name="packagesToScan" value="com.company.project.model"/>
<property name="hibernateProperties">
<props>
<prop key="hibernate.dialect">org.hibernate.dialect.MySQLDialect</prop>
<!-- <prop key="hibernate.current_session_context_class">thread</prop>-->
<prop key="hibernate.cache.region.factory_class">org.hibernate.cache.ehcache.EhCacheRegionFactory</prop>
<prop key="hibernate.cache.use_second_level_cache">true</prop>
<prop key="hibernate.cache.use_query_cache">true</prop>
<prop key="hibernate.show_sql">false</prop>
<prop key="hibernate.id.new_generator_mappings">false</prop>
<prop key="net.sf.ehcache.configurationResourceName">ehcache.xml</prop>
<prop key="hibernate.connection.provider_class">org.hibernate.connection.C3P0ConnectionProvider</prop>
<prop key="hibernate.connection.driver_class">${jdbc.driverClassName}</prop>
<prop key="hibernate.connection.url">${jdbc.url}</prop>
<prop key="hibernate.connection.username">${jdbc.username}</prop>
<prop key="hibernate.connection.password">${jdbc.password}</prop>
<!-- <prop key="hibernate.connection.provider_class">org.hibernate.service.jdbc.connections.internal.C3P0ConnectionProvider</prop>-->
<prop key="hibernate.c3p0.acquire_increment">1</prop>
<prop key="hibernate.c3p0.idle_test_period">300</prop>
<prop key="hibernate.c3p0.max_size">20</prop>
<prop key="hibernate.c3p0.max_statements">100</prop>
<prop key="hibernate.c3p0.min_size">3</prop>
<prop key="hibernate.c3p0.preferredTestQuery">SELECT 1;</prop>
<prop key="hibernate.c3p0.testConnectionOnCheckin">true</prop>
</props>
</property>
</bean>
<bean id="transactionManager" class="org.springframework.orm.hibernate5.HibernateTransactionManager">
<property name="sessionFactory" ref="sessionFactory" />
</bean>
<bean id="shiroFilter" class= "org.apache.shiro.spring.web.ShiroFilterFactoryBean">
<property name="securityManager" ref="securityManager"/>
<property name="loginUrl" value="/verify.jsp"/>
<property name="successUrl" value="/index"/>
<property name="filterChainDefinitions">
<value>
/verify.jsp = authc
/secure/** = authc
/logout.htm = logout
/api/test/** = anon
/api/** = jwtv
</value>
</property>
</bean>
<bean id="logout" class="org.apache.shiro.web.filter.authc.LogoutFilter">
<property name="redirectUrl" value="/login.jsp"/>
</bean>
<bean id="annon" class="org.apache.shiro.web.filter.authc.AnonymousFilter">
</bean>
<bean id="jwtg" class="com.company.project.model.api.ApiGuard">
</bean>
<bean id="jwtv" class="com.company.project.model.api.JWTVerifyingFilter">
</bean>
<bean id="securityManager" class="org.apache.shiro.web.mgt.DefaultWebSecurityManager">
<!-- Single realm app. If you have multiple realms, use the 'realms' property instead. -->
<property name="realm" ref="jdbcRealm"/>
<property name="cacheManager" ref="cacheManager"/>
<!-- By default the servlet container sessions will be used. Uncomment this line
to use shiro's native sessions (see the JavaDoc for more): -->
<!-- <property name="sessionMode" value="native"/> -->
</bean>
<bean id="lifecycleBeanPostProcessor" class="org.apache.shiro.spring.LifecycleBeanPostProcessor"/>
<!-- Enable Shiro Annotations for Spring-configured beans. Only run after
the lifecycleBeanProcessor has run: -->
<bean id="annotationProxy"
class="org.springframework.aop.framework.autoproxy.DefaultAdvisorAutoProxyCreator"
depends-on="lifecycleBeanPostProcessor" />
<bean
class="org.apache.shiro.spring.security.interceptor.AuthorizationAttributeSourceAdvisor">
<property name="securityManager" ref="securityManager" />
</bean>
<bean id="jdbcRealm" class="org.apache.shiro.realm.jdbc.JdbcRealm">
<property name="credentialsMatcher" ref = "sha256Matcher"/>
<property name="authenticationQuery" value = "SELECT password, salt FROM admin WHERE email = ?"/>
<property name="permissionsLookupEnabled" value = "true"/>
<property name="userRolesQuery" value = "SELECT role_name FROM admin_role WHERE email = ?"/>
<property name="permissionsQuery" value = "SELECT permission FROM roles_permission WHERE role_name = ?"/>
<property name="saltStyle" value = "COLUMN"/>
<property name="dataSource" ref = "dataSource"/>
</bean>
<bean id="sha256Matcher" class="org.apache.shiro.authc.credential.HashedCredentialsMatcher" >
<property name="hashAlgorithmName" value = "SHA-256"/>
</bean>
<bean id="cacheManager" class="org.apache.shiro.cache.MemoryConstrainedCacheManager" />
<bean id="multipartResolver" class="org.springframework.web.multipart.commons.CommonsMultipartResolver">
<property name="maxUploadSize" value="10000000"/>
</bean>
</beans>
If I comment out the part:
<bean id="annotationProxy"
class="org.springframework.aop.framework.autoproxy.DefaultAdvisorAutoProxyCreator"
depends-on="lifecycleBeanPostProcessor" />
<bean
class="org.apache.shiro.spring.security.interceptor.AuthorizationAttributeSourceAdvisor">
<property name="securityManager" ref="securityManager" />
</bean>
the project runs but the #RequiresPermissions annotation is useless. When I run the project with these config Error is:
[http-nio-8084-exec-100] WARN
org.springframework.web.context.support.XmlWebApplicationContext -
Exception encountered during context initialization - cancelling
refresh attempt:
org.springframework.beans.factory.UnsatisfiedDependencyException:
Error creating bean with name 'myController': Unsatisfied
dependency expressed through field 'myService'; nested exception
is org.springframework.beans.factory.BeanNotOfRequiredTypeException:
Bean named 'myService' is expected to be of type
[com.company.project.service.myService] but was actually of type
[com.sun.proxy.$Proxy530] [http-nio-8084-exec-100] ERROR
org.springframework.web.context.ContextLoader - Context initialization
failed
org.springframework.beans.factory.UnsatisfiedDependencyException:
Error creating bean with name 'myController': Unsatisfied
dependency expressed through field 'myService'; nested exception
is org.springframework.beans.factory.BeanNotOfRequiredTypeException:
Bean named 'myService' is expected to be of type
[com.company.project.service.myService] but was actually of type
[com.sun.proxy.$Proxy530] at
org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor$AutowiredFieldElement.inject(AutowiredAnnotationBeanPostProcessor.java:569)
My controller classes are smth like:
#RestController
#RequestMapping(value = "/api/my")
public class MyApis {
#Autowired
MyService myService;
#RequestMapping(method = RequestMethod.GET, value = "/profile/save")
#RequiresPermissions("profile:save")
public void saveProfile(#RequestParam(value = "first-name") String firstName, #RequestParam(value = "last-name") String lastName,HttpServletRequest request) {
Profile profile = new Profile();
profile.setFirstName(firstName);
profile.setLastName(lastName);
myService.insert(profile);
}
}
Please help me figure out setting up Shiro annotations. Thank you.
Shiro has a Spring Boot example that uses Shiro's annotations on a controller. And a non-boot example too

integrating tiles in spring3, getting java.lang.NoSuchFieldError: PATCH exception

Let me know how to initialize tiles from dispatcher and application context and if any changes required in web.xml,
this is my tiles.xml
<definition name="contact" extends="mainLayout">
<put-attribute name="title" value="Contact Manager" />
<put-attribute name="body" value="/WEB-INF/jsp/contact.jsp" />
</definition>
</tiles-definitions>
in application context i have used
<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="requestContextAttribute" value="requestContext"/>
<property name="viewClass" value="org.springframework.web.servlet.view.tiles2.TilesView"/>
</bean>
and dispatcher looks like this
<bean class="org.springframework.web.servlet.mvc.support.ControllerClassNameHandlerMapping"/>
indexController</prop>-->
newController
<bean class="org.springframework.web.servlet.view.tiles2.TilesConfigurer" id="tilesConfigurer">
<property name="definitions">
<list>
<value>WEB-INF/tiles.xml</value>
</list>
</property>
</bean>
<bean class="org.springframework.web.servlet.view.UrlBasedViewResolver" id="viewResolver">
<property name="viewClass">
<value>
org.springframework.web.servlet.view.tiles2.TilesView
</value>
</property>
In Dispatcher-Servlet
<bean id="tilesConfigurer" class="org.springframework.web.servlet.view.tiles2.TilesConfigurer">
<property name="definitions">
<list>
<value>/WEB-INF/tiles.xml</value>
</list>
</property>
</bean>
In web.xml use this code
<listener>
<listener-class>org.apache.tiles.web.startup.simple.SimpleTilesListener</listener-class>
</listener>
rest is not required for spring-tiles application, tiles.xml is depended on your requirement

setting up an sql connection to run a spring-mvc project, using intelliJ

I've cloned a spring-mvc project to my computer and trying to get it running using intelliJ. It seems, according to this that I need to establish an SQL connection. Do I need to download mysql to my computer, create an account and enter that information in my connection.XML file (seen 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"
xsi:schemaLocation="
http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-3.0.xsd">
<!-- Data Source Setup -->
<bean id="hsqldataSource" class="org.springframework.jdbc.datasource.DriverManagerDataSource">
<property name="driverClassName" value="org.hsqldb.jdbcDriver" />
<property name="url" value="jdbc:hsqldb:hsql" />
<property name="username" value="example" />
<property name="password" value="example" />
</bean>
<bean id="mysqldataSource" class="org.springframework.jdbc.datasource.DriverManagerDataSource">
<property name="driverClassName" value="com.mysql.jdbc.Driver" />
<property name="url" value="jdbc:mysql://192.168.0.0.0:3306/dev" />
<property name="username" value="example" />
<property name="password" value="example" />
</bean>
<bean id="sessionFactory" class="org.springframework.orm.hibernate3.LocalSessionFactoryBean">
<property name="mappingResources">
<list>
<value>example/peer-review/domain/hibernatemapping/Division.hbm.xml</value>
<value>example/peer-review/domain/hibernatemapping/Modality.hbm.xml</value>
<value>example/peer-review/domain/hibernatemapping/Score.hbm.xml</value>
<value>example/peer-review/domain/hibernatemapping/User.hbm.xml</value>
<value>example/peer-review/domain/hibernatemapping/QaCase.hbm.xml</value>
<value>example/peer-review/domain/hibernatemapping/Review.hbm.xml</value>
<value>example/peer-review/domain/hibernatemapping/Exam.hbm.xml</value>
<value>example/peer-review/domain/hibernatemapping/Patient.hbm.xml</value>
<value>example/peer-review/domain/hibernatemapping/Role.hbm.xml</value>
</list>
</property>
<property name="hibernateProperties">
<props>
<prop key="hibernate.show_sql">false</prop>
<prop key="hibernate.hbm2ddl.auto">create</prop>
</props>
</property>
<property name="dataSource" ref="hsqldataSource" />
</bean>
<bean id="transactionManager" class="org.springframework.orm.hibernate3.HibernateTransactionManager">
<property name="sessionFactory" ref="sessionFactory" />
</bean>
<!-- Dao Layer generic config-->
<bean id="abstractDaoTarget" class="example.peer-review.persistence.hibernate.GenericDAOHibernateImpl" abstract="true">
<property name="sessionFactory" ref="sessionFactory"/>
</bean>
<!-- Dao Layer instances -->
<bean id="DivisionDAO" parent="abstractDaoTarget" class="example.peer-review.persistence.hibernate.DivisionDAOHibernateImpl" />
<bean id="ModalityDAO" parent="abstractDaoTarget" class="example.peer-review.persistence.hibernate.ModalityDAOHibernateImpl" />
<bean id="ScoreDAO" parent="abstractDaoTarget" class="example.peer-review.persistence.hibernate.ScoreDAOHibernateImpl" />
<bean id="UserDAO" parent="abstractDaoTarget" class="example.peer-review.persistence.hibernate.UserDAOHibernateImpl" />
<bean id="ReviewDAO" parent="abstractDaoTarget" class="example.peer-review.persistence.hibernate.ReviewDAOHibernateImpl" />
<bean id="QaCaseDAO" parent="abstractDaoTarget" class="example.peer-review.persistence.hibernate.QaCaseDAOHibernateImpl" />
<bean id="ExamDAO" parent="abstractDaoTarget" class="example.peer-review.persistence.hibernate.ExamDAOHibernateImpl" />
<bean id="PatientDAO" parent="abstractDaoTarget" class="example.peer-review.persistence.hibernate.PatientDAOHibernateImpl" />
<bean id="RoleDAO" parent="abstractDaoTarget" class="example.peer-review.persistence.hibernate.RoleDAOHibernateImpl" />
<bean id="contextSource" class="org.springframework.ldap.core.support.LdapContextSource">
<property name="url" value="ldap://example.edu:1234" />
<property name="base" value="" />
<property name="userDn" value="cn=Test1" />
<property name="password" value="Test1" />
<property name="authenticationStrategy" ref="ldapAuthStrat" />
</bean>
<bean id="ldapTemplate" class="org.springframework.ldap.core.LdapTemplate">
<constructor-arg ref="contextSource" />
</bean>
<bean id="ldapAuthStrat" class="org.springframework.ldap.core.support.ExternalTlsDirContextAuthenticationStrategy" />
</beans>
Your conf file contains the definition for two different datasources, hsql and mysql. hsql is an in memory db.
Mysql is standalone database application.
yes to connect to the mysql source, you need to download mysql and set up users/schema.

Not able to wire entityManager with applicationContext bean

I am facing a problem to wire entity manager with the bean present in application context.
whenever i do some operation it gives NullPointerException.
this is my applicationContext.xml 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:context="http://www.springframework.org/schema/context"
xmlns:tx="http://www.springframework.org/schema/tx"
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.ajit.retail"/>
<bean id="dataSource" class="org.springframework.jdbc.datasource.DriverManagerDataSource">
<property name="driverClassName" value="org.postgresql.Driver"/>
<property name="url" value="jdbc:postgresql://localhost/retail"/>
<property name="username" value="retail_user"/>
<property name="password" value="password"/>
</bean>
<bean id="entityManagerOne" class="org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean">
<property name="dataSource" ref="dataSource"/>
<property name="jpaVendorAdapter">
<bean class="org.springframework.orm.jpa.vendor.HibernateJpaVendorAdapter">
<property name="showSql" value="true"/>
<property name="databasePlatform" value="org.hibernate.dialect.PostgreSQL82Dialect"/>
</bean>
</property>
</bean>
<bean id="transactionManager" class="org.springframework.orm.jpa.JpaTransactionManager">
<property name="entityManagerFactory" ref="entityManagerOne"/>
</bean>
<tx:annotation-driven transaction-manager="transactionManager"/>
</beans>
this is the java file in which i am creating the entity manager
import javax.persistence.EntityManager;
import javax.persistence.PersistenceContext;
public class AbstractRepository {
#PersistenceContext
EntityManager entityManager;
}
so whenever i use this entity manager it gives null pointer exception
please help!
Your entity manager bean is called enetityManagerOne, but the variable is called entityManager. Maybe renamme your bean in your XML file:
<bean id="entityManager" class="org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean">
Another solution could be you forgot the following bean declarations:
For the support for transaction:
<tx:annotation-driven/>
The support for parsing JPA annotations:
<bean class="org.springframework.orm.jpa.support.PersistenceAnnotationBeanPostProcessor"/>
my application context was not on the correct place (src/main/resources). Now I put that there and its working.
Use this code in your dispatcher-servlet.xml
<bean id="persistenceUnitManager" class="org.springframework.orm.jpa.persistenceunit.DefaultPersistenceUnitManager">
<property name="persistenceXmlLocations">
<list>
<value>classpath*:META-INF/persistence.xml</value>
</list>
</property>
<property name="defaultDataSource" ref="dataSource"/>
</bean>
<bean id="entityManagerFactory" class="org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean">
<property name="persistenceUnitManager" ref="persistenceUnitManager"/>
<property name="persistenceUnitName" value="etray"/>
</bean>
<jee:jndi-lookup id="dataSource" jndi-name="java:/prateek" />
<!-- we plan to use JTA transactions and declare them using annotations -->
<bean id="transactionManager"
class="org.springframework.transaction.jta.JtaTransactionManager" />
<tx:annotation-driven transaction-manager="transactionManager" />
<!-- to inject instances of EntityManager using #PersistenceContext annotation -->
<bean
class="org.springframework.orm.jpa.support.PersistenceAnnotationBeanPostProcessor" />
it resolve my problem, hope it will help.

Spring MVC internalization, only english messages are displayed. But the address bar changes

--------------------UPDATE!-------------here is my .jsp withouth unnecessairy buttons
<%# page language="java" contentType="text/html; charset=ISO-8859-1"
pageEncoding="ISO-8859-1"%>
<%#taglib uri="http://www.springframework.org/tags/form" prefix="form"%>
<%#taglib uri="http://www.springframework.org/tags" prefix="spring"%>
<%# taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<html>
<head>
<title>Practice</title>
<link rel="stylesheet" type="text/css" href="style/wort.css" />
</head>
<body>
<a href="goToDictionary.html" class="practice_dictionary"><spring:message code="check.the.dictionary" />
</a>
<br>
en
de
<br>
</body>
</html>
----------------------------------Update ends here----------------------------------------
I have set up i18n to my web app using Spring MVC. It does not work.
When I click on the link:
de
nothing happens, only the address bar changes to
http://localhost:8080/wort/register.html?lang=de
but the displayed messages remain the same (english).
Obviously I have the messages_de.properties file next to the messages_en.properties file.
(there is no problem with the english messages' display.)
Do I miss something obvious?
here is my spring configuration:
<?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:tx="http://www.springframework.org/schema/tx" xmlns:mvc="http://www.springframework.org/schema/mvc"
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/mvc http://www.springframework.org/schema/mvc/spring-mvc.xsd">
<context:property-placeholder location="classpath:jdbc.properties" />
<context:component-scan base-package="net" />
<mvc:annotation-driven />
<tx:annotation-driven transaction-manager="hibernateTransactionManager" />
<bean id="messageSource"
class="org.springframework.context.support.ReloadableResourceBundleMessageSource">
<property name="basename" value="classpath:messages" />
<property name="defaultEncoding" value="UTF-8" />
</bean>
<bean id="localeChangeInterceptor"
class="org.springframework.web.servlet.i18n.LocaleChangeInterceptor">
<property name="paramName" value="lang" />
</bean>
<bean id="localeResolver"
class="org.springframework.web.servlet.i18n.CookieLocaleResolver">
<property name="defaultLocale" value="en" />
</bean>
<bean id="handlerMapping"
class="org.springframework.web.servlet.mvc.annotation.DefaultAnnotationHandlerMapping">
<property name="interceptors">
<ref bean="localeChangeInterceptor" />
</property>
</bean>
<bean id="jspViewResolver"
class="org.springframework.web.servlet.view.InternalResourceViewResolver">
<property name="viewClass"
value="org.springframework.web.servlet.view.JstlView" />
<property name="prefix" value="/WEB-INF/jsp/" />
<property name="suffix" value=".jsp" />
</bean>
<bean id="dataSource"
class="org.springframework.jdbc.datasource.DriverManagerDataSource">
<property name="driverClassName" value="${database.driver}" />
<property name="url" value="${database.url}" />
<property name="username" value="${database.user}" />
<property name="password" value="${database.password}" />
</bean>
<bean id="sessionFactory"
class="org.springframework.orm.hibernate3.annotation.AnnotationSessionFactoryBean">
<property name="dataSource" ref="dataSource" />
<property name="annotatedClasses">
<list>
<value>net.model.Word</value>
<value>net.model.Category</value>
<value>net.model.Challenge</value>
<value>net.model.User</value>
</list>
</property>
<property name="hibernateProperties">
<props>
<prop key="hibernate.dialect">${hibernate.dialect}</prop>
<prop key="hibernate.show_sql">${hibernate.show_sql}</prop>
</props>
</property>
</bean>
<bean id="hibernateTransactionManager"
class="org.springframework.orm.hibernate3.HibernateTransactionManager">
<property name="sessionFactory" ref="sessionFactory" />
</bean>
here is the solution: I have to remove this from spring-servlet.xml and everything is fine
<mvc:annotation-driven />

Resources