I am deploying my Spring-Hibernate web application on "https://app.j.layershift.co.uk/" server. But it is showing error "The requested resource is not available".
This is very small web application on Spring-Hibernate. I made a zip file and upload it on server but server gives error at time of deployment.
Dispatcher Servlet:
<bean id="cradentials" class="com.webscreen.bean.Cradentials" />
<bean id="cradentialsService" class="com.webscreen.service.CradentialsService"/>
<bean id="cradentialsDao" class="com.webscreen.dao.CradentialsDao"/>
<bean id="viewResolver"
class="org.springframework.web.servlet.view.InternalResourceViewResolver">
<property name="prefix">
<value>/WEB-INF/views/</value>
</property>
<property name="suffix">
<value>.jsp</value>
</property>
</bean>
<context:component-scan base-package="com.webscreen.controller"></context:component-scan>
<!-- we will manage transactions with annotations -->
<tx:annotation-driven />
<bean id="transactionManager"
class="org.springframework.orm.hibernate4.HibernateTransactionManager">
<property name="sessionFactory" ref="sessionFactory" />
</bean>
<!-- we can use annotations -->
<context:annotation-config />
<mvc:annotation-driven />
<!-- data source for our database -->
<bean id="dataSource" class="com.mchange.v2.c3p0.ComboPooledDataSource" destroy-method="close">
<property name="driverClass" value="com.mysql.jdbc.Driver" />
<property name="jdbcUrl" value="jdbc:mysql://localhost:3306/screenshots" />
<property name="user" value="root" />
<property name="password" value="root" />
<property name="maxPoolSize" value="10" />
<property name="maxStatements" value="0" />
<property name="minPoolSize" value="5" />
</bean>
<!-- configure hibernate session factory -->
<bean id="sessionFactory" class="org.springframework.orm.hibernate4.LocalSessionFactoryBean">
<property name="dataSource" ref="dataSource" />
<property name="annotatedClasses">
<list>
<value>com.webscreen.bean.Cradentials</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">update</prop>
</props>
</property>
</bean>
</beans>
Web.xml
<?xml version="1.0" encoding="UTF-8"?>
<web-app id="WebApp_9" 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">
<welcome-file-list>
<welcome-file>index.jsp</welcome-file>
</welcome-file-list>
<servlet>
<servlet-name>dispatcher</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>dispatcher</servlet-name>
<url-pattern>*.do</url-pattern>
</servlet-mapping>
</web-app>
Related
This is the bean with this id defined in my spring-servlet.xml file
<bean id="dataSource"
class="org.apache.commons.dbcp.BasicDataSource" destroy-method="close"
p:driverClassName="${jdbc.driverClassName}"
p:url="${jdbc.databaseurl}" p:username="${jdbc.username}"
p:password="${jdbc.password}" />
This is the complete stacktrace
SEVERE: Exception sending context initialized event to listener instance of class org.springframework.web.context.ContextLoaderListener
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'org.springframework.dao.annotation.PersistenceExceptionTranslationPostProcessor#0': Initialization of bean failed; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'entityManagerFactory' defined in class path resource [META-INF/spring/hibernate-context.xml]: Cannot resolve reference to bean 'dataSource' while setting bean property 'dataSource'; nested exception is org.springframework.beans.factory.NoSuchBeanDefinitionException: No bean named 'dataSource' is defined
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:529)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:458)
at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:295)
this is my application context file defined in my WEB-INF folder
<?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">
</beans>
this is my complete web.xml file
<?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>YummyFoods</display-name>
<welcome-file-list>
<welcome-file>/JSP/welcome.jsp</welcome-file>
</welcome-file-list>
<listener>
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>
<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>
<servlet>
<servlet-name>imageServlet</servlet-name>
<servlet-class>com.yummyfoods.spring.servlet.ImageServlet</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>imageServlet</servlet-name>
<url-pattern>/image/*</url-pattern>
</servlet-mapping>
<error-page>
<error-code>404</error-code>
<location>/error</location>
</error-page>
</web-app>
this is my spring-servlet.xml file
<mvc:resources location="/resources/" mapping="/resources/**"/>
<mvc:default-servlet-handler/>
<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="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="classpath:jdbc.properties" />
<bean id="dataSource"
class="org.apache.commons.dbcp.BasicDataSource" destroy-method="close"
p:driverClassName="${jdbc.driverClassName}"
p:url="${jdbc.databaseurl}" p:username="${jdbc.username}"
p:password="${jdbc.password}" />
<bean id="sessionFactory"
class="org.springframework.orm.hibernate3.LocalSessionFactoryBean">
<property name="dataSource" ref="dataSource" />
<property name="configLocation">
<value>classpath:hibernate-cfg.xml</value>
</property>
<property name="configurationClass">
<value>org.hibernate.cfg.AnnotationConfiguration</value>
</property>
<property name="hibernateProperties">
<props>
<prop key="hibernate.dialect">${jdbc.dialect}</prop>
<prop key="hibernate.show_sql">true</prop>
<prop key="hibernate.connection.SetBigStringTryClob">true</prop>
<prop key="hibernate.jdbc.batch_size">0</prop>
</props>
</property>
</bean>
<bean id="multipartResolver"
class="org.springframework.web.multipart.commons.CommonsMultipartResolver">
<!-- one of the properties available; the maximum file size in bytes -->
<property name="maxUploadSize" value="10000000" />
</bean>
<tx:annotation-driven />
<bean id="transactionManager"
class="org.springframework.orm.hibernate3.HibernateTransactionManager">
<property name="sessionFactory" ref="sessionFactory" />
</bean>
</beans>
Please assist me find my way.
From the look of things you are defining a dataSource in a DispatcherServlet context configuration file i.e spring-servlet.xml as you have specified. And the entityManagerFactory in a root application context file. Beans in the root application context cannot reference those in the servlet application context file. You need to move your dataSource bean to the hibernate-context.xml file.
What comes with your dependecies? I think you should include your datasource def in applicationContext.xml and then the hibernate thing should be happy.
So...
the
<bean id="dataSource"
class="org.apache.commons.dbcp.BasicDataSource" destroy-method="close"
p:driverClassName="${jdbc.driverClassName}"
p:url="${jdbc.databaseurl}" p:username="${jdbc.username}"
p:password="${jdbc.password}" />
<bean id="sessionFactory"
class="org.springframework.orm.hibernate3.LocalSessionFactoryBean">
<property name="dataSource" ref="dataSource" />
<property name="configLocation">
<value>classpath:hibernate-cfg.xml</value>
</property>
<property name="configurationClass">
<value>org.hibernate.cfg.AnnotationConfiguration</value>
</property>
<property name="hibernateProperties">
<props>
<prop key="hibernate.dialect">${jdbc.dialect}</prop>
<prop key="hibernate.show_sql">true</prop>
<prop key="hibernate.connection.SetBigStringTryClob">true</prop>
<prop key="hibernate.jdbc.batch_size">0</prop>
</props>
</property>
</bean>
<tx:annotation-driven />
<bean id="transactionManager"
class="org.springframework.orm.hibernate3.HibernateTransactionManager">
<property name="sessionFactory" ref="sessionFactory" />
</bean>
goes in applicationContext.xml and is removed from spring-servlet.xml
Then the hibernate-cfg.xml wich is embeded in the Session factory def should find it's data source and be happy at loading.
It's better to isolate servlet mapping and mvc definitions from back end stuff (bean factory etc...) as it is easier to change it in the future if needed.
With what do you build your app?
I am new to Spring-MVC, i am trying to create a Spring-MVC project that uses annotation in controller and also creates databases.
The application works fine, when i write all the xml code in spring-dispatcher-servlet.xml file, but when i separate spring database connection xml and spring servlet xml file, it stops working.
The following code successfully creates tables in database, but it fails to load controllers, it gives me 404 not found page when i try to hit any controller.
If i comment <listner> code in my web.xml file it successfully loads all the controllers, but no database operations performed.
Kindly guide me what i am doing wrong here.
web.xml
<!-- JPA -->
<listener>
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>/WEB-INF/spring.xml</param-value>
</context-param>
<!-- Servlet Dispatcher -->
<servlet>
<servlet-name>spring-dispatcher</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>spring-dispatcher</servlet-name>
<url-pattern>/</url-pattern>
</servlet-mapping>
<servlet-mapping>
<servlet-name>default</servlet-name>
<url-pattern>*.css</url-pattern>
</servlet-mapping>
Spring.xml
<mvc:annotation-driven />
<context:annotation-config />
<context:component-scan base-package="com.evantage.models" />
<bean id="dataSource"
class="org.springframework.jdbc.datasource.DriverManagerDataSource">
<property name="driverClassName" value="com.mysql.jdbc.Driver" />
<property name="url" value="jdbc:mysql://localhost:3306/springDB" />
<property name="username" value="root" />
<property name="password" value="" />
</bean>
<!-- This produces a container-managed EntityManagerFactory; rather than
application-managed EntityManagerFactory as in case of LocalEntityManagerFactoryBean -->
<bean id="transactionManager" class="org.springframework.orm.jpa.JpaTransactionManager"/>
<bean class="org.springframework.orm.jpa.support.PersistenceAnnotationBeanPostProcessor"/>
<bean id="entityManagerFactory" class="org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean">
<property name="persistenceProviderClass" value="org.hibernate.ejb.HibernatePersistence"/>
<property name="dataSource" ref="dataSource"/>
<property name="persistenceUnitName" value="persistenceUnit"/>
<property name="persistenceXmlLocation" value="/WEB-INF/persistence.xml" />
</bean>
<jpa:repositories base-package="com.evantagesoft.springmvctiles.repository"
entity-manager-factory-ref="entityManagerFactory"
transaction-manager-ref="transactionManager"/>
<tx:annotation-driven transaction-manager="transactionManager" />
</beans>
Spring-dispatcher-servlet.xml
<context:component-scan base-package="com.evantage.controllers" />
<mvc:annotation-driven />
<bean id="tilesConfigurer"
class="org.springframework.web.servlet.view.tiles2.TilesConfigurer">
<property name="definitions">
<list>
<value>/WEB-INF/tiles.xml</value>
</list>
</property>
<property name="preparerFactoryClass"
value="org.springframework.web.servlet.view.tiles2.SpringBeanPreparerFactory" />
</bean>
<!-- View Handler -->
<bean
class="org.springframework.web.servlet.view.ContentNegotiatingViewResolver">
<property name="favorPathExtension" value="true" />
<property name="mediaTypes">
<map>
<entry key="xml" value="text/xml" />
<entry key="json" value="application/json" />
<entry key="html" value="text/html" />
<entry key="less" value="text/html" />
</map>
</property>
<property name="viewResolvers">
<list>
<bean class="org.springframework.web.servlet.view.UrlBasedViewResolver">
<property name="viewClass"
value="org.springframework.web.servlet.view.tiles2.TilesView" />
</bean>
<bean
class="org.springframework.web.servlet.view.InternalResourceViewResolver">
<!-- <property name="prefix" value="/"/> -->
<property name="prefix">
<value>/WEB-INF/</value>
</property>
<property name="suffix">
<value>.jsp</value>
</property>
</bean>
</list>
</property>
</bean>
You need to add context:component-scan base-package="controller package" in dispatcher servlet xml to make it work.
Component scan is required to scan the package and register your controller classes
I can't persist data in the db using the injected entitymgr in spring mvc. I've try with a lot of similar questions, but none of the answers seem to solve my issue.
I have a config like:
applicationContext.xml
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="...">
<import resource="config-context.xml"/>
<context:annotation-config />
<tx:annotation-driven />
<context:component-scan base-package="org.springbyexample.orm.jpa.inheritance.dao" />
<bean class="org.springframework.transaction.interceptor.TransactionAttributeSourceAdvisor">
<property name="transactionInterceptor" ref="transactionInterceptorIkConf"/>
<property name="classFilter">
<bean class="org.springframework.aop.aspectj.TypePatternClassFilter">
<constructor-arg value="com.package..*"></constructor-arg>
</bean>
</property>
</bean>
<bean id="transactionInterceptorIkConf"
class="org.springframework.transaction.interceptor.TransactionInterceptor">
<property name="transactionManager" ref="transactionManager"/>
<property name="transactionAttributeSource">
<bean class="org.springframework.transaction.annotation.AnnotationTransactionAttributeSource"/>
</property>
</bean>
</beans>
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="...">
<import resource="config-context.xml"/>
<context:annotation-config />
<tx:annotation-driven />
<context:component-scan base-package="org.springbyexample.orm.jpa.inheritance.dao" />
<bean class="org.springframework.transaction.interceptor.TransactionAttributeSourceAdvisor">
<property name="transactionInterceptor" ref="transactionInterceptorIkConf"/>
<property name="classFilter">
<bean class="org.springframework.aop.aspectj.TypePatternClassFilter">
<constructor-arg value="com.package..*"></constructor-arg>
</bean>
</property>
</bean>
<bean id="transactionInterceptorIkConf"
class="org.springframework.transaction.interceptor.TransactionInterceptor">
<property name="transactionManager" ref="transactionManager"/>
<property name="transactionAttributeSource">
<bean class="org.springframework.transaction.annotation.AnnotationTransactionAttributeSource"/>
</property>
</bean>
</beans>
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="...">
<import resource="config-context.xml"/>
<context:annotation-config />
<tx:annotation-driven />
<context:component-scan base-package="org.springbyexample.orm.jpa.inheritance.dao" />
<bean class="org.springframework.transaction.interceptor.TransactionAttributeSourceAdvisor">
<property name="transactionInterceptor" ref="transactionInterceptorIkConf"/>
<property name="classFilter">
<bean class="org.springframework.aop.aspectj.TypePatternClassFilter">
<constructor-arg value="com.package..*"></constructor-arg>
</bean>
</property>
</bean>
<bean id="transactionInterceptorIkConf"
class="org.springframework.transaction.interceptor.TransactionInterceptor">
<property name="transactionManager" ref="transactionManager"/>
<property name="transactionAttributeSource">
<bean class="org.springframework.transaction.annotation.AnnotationTransactionAttributeSource"/>
</property>
</bean>
</beans>
in config-context.xml:
<?xml version="1.0" encoding="UTF-8"?>
<beans ...>
<context:property-placeholder location="..."
ignore-unresolvable="true" order="1" ignore-resource-not-found="true"/>
<context:property-placeholder location="classpath:config.properties"
order="2"/>
<context:component-scan base-package="com.package" >
<context:exclude-filter type="regex" expression=".*controller\.[^.]*"/>
</context:component-scan>
<!-- Handler for serving static content -->
<bean id="ikconfStaticResources" class="org.springframework.web.servlet.resource.ResourceHttpRequestHandler">
<property name="locations">
<list>
<value>classpath:/META-INF/resources/static/</value>
</list>
</property>
</bean>
<bean id="emf" class="org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean">
<property name="persistenceUnitName" value="conf-persistence"/>
<property name="dataSource" ref="ikconfDataSource" />
<property name="packagesToScan" value="com.ikusi.ikconf" />
<property name="jpaVendorAdapter">
<bean class="org.springframework.orm.jpa.vendor.HibernateJpaVendorAdapter" />
</property>
<property name="jpaDialect">
<bean class="org.springframework.orm.jpa.vendor.HibernateJpaDialect" />
</property>
<property name="jpaProperties">
<props>
<prop key="hibernate.dialect">${jdbc.dialect}</prop>
<prop key="hibernate.show_sql">${hibernate.show_sql}</prop>
<prop key="hibernate.hbm2ddl.auto">${hibernate.hbm2ddl.auto}</prop>
</props>
</property>
</bean>
<bean id="ikconfDataSource" class="org.springframework.jdbc.datasource.DriverManagerDataSource">
<property name="driverClassName" value="${jdbc.driverClassName}" />
<property name="url" value="${db.url}" />
<property name="username" value="${db.username}" />
<property name="password" value="${db.password}" />
</bean>
<bean id="transactionManager" class="org.springframework.orm.jpa.JpaTransactionManager" p:entityManagerFactory-ref="emf" autowire="byName"/>
</beans>
in mvc-dispacher-servlet.xml
<?xml version="1.0" encoding="UTF-8"?>
<beans ...>
<context:component-scan base-package="com.package" >
<context:include-filter type="regex" expression=".*controller\.[^.]*"/>
</context:component-scan>
<mvc:resources mapping="/resources/**" location="/WEB-INF/static/" />
<mvc:annotation-driven />
<bean
class="org.springframework.web.servlet.view.InternalResourceViewResolver">
<property name="prefix">
<value>/WEB-INF/pages/</value>
</property>
<property name="suffix">
<value>.jsp</value>
</property>
</bean>
</beans>
inside web.xml
<?xml version="1.0" encoding="UTF-8"?>
<web-app ...>
<display-name>demo-app</display-name>
<!-- Spring context -->
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>/WEB-INF/applicationContext.xml</param-value>
</context-param>
<!-- Spring MVC -->
<servlet>
<servlet-name>mvc-dispatcher</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
<init-param>
<param-name>contextConfiglocation</param-name>
<param-value>/WEB-INF/mvc-dispatcher-servlet.xml</param-value>
</init-param>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>mvc-dispatcher</servlet-name>
<url-pattern>/</url-pattern>
</servlet-mapping>
<listener>
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>
</web-app>
Now I have one controller
#Controller
#RequestMapping("/main")
public class MainController {
#Autowired
private OneService service; //with getters and setters
#RequestMapping(value = "/url", method = RequestMethod.POST, headers = { "Content-type=application/json" })
public #ResponseBody Data move(#RequestBody Data data) {
getService().doSomething(data);
}
}
and a service
#Service
public class OneService {
#Autowired
private OneDao dao;
#Transactional(readOnly = false, propagation = Propagation.REQUIRES_NEW, rollbackFor = { IkfBusinessException.class })
public void doSomething(Data data) {
//Do the actual logic inside transaction
}
#PersistenceContext(unitName = "conf-persistence")
#Override
protected void setEntityManager(EntityManager em) {
this.em = em;
}
}
I'm having this error: javax.persistence.TransactionRequiredException: no transaction is in progress when I'm calling the service from my controller.
But when I run it with a Bootstrap class it works properly.
I think I have something wrong with my MVC config.
I have one possible sollution:
I change my component scan inside mvc-servlet like:
<context:component-scan base-package="com.package.controller"/>
To add only my controllers, since "context:include-filter" doesn't include exclusively indicated packages.
With this config it's working now. Maybe there is a better config.
Anyway thanks you all for your time, and if you have any more suggestions you can reply.
Thanks
I'm developping a web application using spring, hibernate and primefaces.
In this application I get data from a database and use it to display charts.
when I run my application I get this error :
org.springframework.beans.factory.NoSuchBeanDefinitionException: No bean named 'springSecurityFilterChain' is defined
This is the application context 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:tx="http://www.springframework.org/schema/tx"
xmlns:util="http://www.springframework.org/schema/util"
xmlns:p="http://www.springframework.org/schema/p"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.5.xsd
http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-2.5.6.SEC01.xsd
http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-2.5.6.SEC01.xsd
http://www.springframework.org/schema/util http://www.springframework.org/schema/util/spring-util-2.5.6.SEC01.xsd
">
<bean id="dataSource" class="org.springframework.jdbc.datasource.DriverManagerDataSource" >
<property name="driverClassName">
<value>com.mysql.jdbc.Driver</value>
</property>
<property name="url">
<value>jdbc:mysql://localhost/biblio?useUnicode=true&characterEncoding=UTF-8&characterSetResults=UTF-8</value>
</property>
<property name="username">
<value>root</value>
</property>
<property name="password">
<value></value>
</property>
</bean>
<bean id="sessionFactory" class="org.springframework.orm.hibernate3.LocalSessionFactoryBean" >
<property name="mappingResources">
<list>
<value>Mapping/Status.hbm.xml</value>
<value>Mapping/Authorities.hbm.xml</value>
<value>Mapping/Livre.hbm.xml</value>
<value>Mapping/Users.hbm.xml</value>
<value>Mapping/Auteur.hbm.xml</value>
<value>Mapping/Emprunteur.hbm.xml</value>
<value>Mapping/Collection.hbm.xml</value>
<value>Mapping/Emprunt.hbm.xml</value>
<value>Mapping/Cathegorie.hbm.xml</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.cglib.use_reflection_optimizer">true</prop>
<prop key="hibernate.cache.provider_class">org.hibernate.cache.HashtableCacheProvider</prop>
</props>
</property>
<property name="dataSource">
<ref bean="dataSource"/>
</property>
</bean>
<!--Spring Data Access Exception Translator Defintion-->
<bean id="jdbcExceptionTranslator" class="org.springframework.jdbc.support.SQLErrorCodeSQLExceptionTranslator" >
<property name="dataSource">
<ref bean="dataSource"/>
</property>
</bean>
<!--Hibernate Template Defintion-->
<bean id="hibernateTemplate" class="org.springframework.orm.hibernate3.HibernateTemplate" >
<property name="sessionFactory">
<ref bean="sessionFactory"/>
</property>
<property name="jdbcExceptionTranslator">
<ref bean="jdbcExceptionTranslator"/>
</property>
</bean>
<!--Hibernate Transaction Manager Definition-->
<bean id="transactionManager" class="org.springframework.orm.hibernate3.HibernateTransactionManager" >
<property name="sessionFactory">
<ref local="sessionFactory"/>
</property>
</bean>
<!--========================= Start of DAO BEANS DEFINITIONS =========================-->
<bean id="autDao" class="Implementation.dao.AuteurDaoImpl" >
<property name="hibernateTemplate" ref="hibernateTemplate"/>
</bean>
<bean id="statusDao" class="Implementation.dao.StatusDaoImpl" >
<property name="hibernateTemplate" ref="hibernateTemplate"/>
</bean>
<bean id="categDao" class="Implementation.dao.CategorieDaoImpl" >
<property name="hibernateTemplate" ref="hibernateTemplate"/>
</bean>
<bean id="empDao" class="Implementation.dao.EmprunteurDaoImpl" >
<property name="hibernateTemplate" ref="hibernateTemplate"/>
</bean>
<bean id="colleDao" class="Implementation.dao.CollectionDaoImpl" >
<property name="hibernateTemplate" ref="hibernateTemplate"/>
</bean>
<bean id="livDao" class="Implementation.dao.LivreDaoImpl" >
<property name="hibernateTemplate" ref="hibernateTemplate"/>
</bean>
<bean id="emprDao" class="Implementation.dao.EmpruntDaoImpl" >
<property name="hibernateTemplate" ref="hibernateTemplate"/>
</bean>
<!--========================= Start of SERVICE BEANS DEFINITIONS =========================-->
<bean id="auDao" class="Implementation.service.AuteurServiceImpl" >
<property name="auteurDao" ref="autDao"/>
</bean>
<bean id="statDao" class="Implementation.service.StatusServiceImpl" >
<property name="statusDao" ref="statusDao"/>
</bean>
<bean id="catDao" class="Implementation.service.CategorieServiceImpl" >
<property name="categorieDao" ref="categDao"/>
</bean>
<bean id="emprunDao" class="Implementation.service.EmprunteurServiceImpl" >
<property name="emprunteurDao" ref="empDao"/>
</bean>
<bean id="collectionDao" class="Implementation.service.CollectionServiceImpl" >
<property name="collectionDao" ref="colleDao"/>
</bean>
<bean id="livrDao" class="Implementation.service.LivreServiceImpl" >
<property name="livreDao" ref="livDao"/>
</bean>
<bean id="empruDao" class="Implementation.service.EmpruntServiceImpl" >
<property name="empruntDao" ref="emprDao"/>
</bean>
</beans>
How can I solve this problem ?
Looks like you are using spring security filter in your application.
Can you post your web.xml?
You have to define in you web.xml
filter>
<filter-name>springSecurityFilterChain</filter-name>
<filter-class>org.springframework.web.filter.DelegatingFilterProxy</filter-class>
</filter>
<filter-mapping>
<filter-name>springSecurityFilterChain</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
I am trying to configure internazionalization in Spring MVC (using changing of locales via links), however, it doesn't seem to be working at all: default locale is always ru for some reason, though default is set to en, they are not changing using links, spring messages are displayed empty regardless of the chosen locale (messages_de, messages_en and messages_ru.properties DO exist at classpath (src/main/resources)). They contain e.g.
label.test=Russian
and i refer to them as
<spring:message code="label.test" />
in my JSPs. They are not being displayed like that.
I take it as even messageSource is not found, even though there are no errors or warnings. I'd really appreciate any help as I'm trying to figure it out for really long time. Apparently, I've missed some details, but I definitely can't catch the problem. Here are my configuration files (or most relevant parts).
root-context.xml
<context:component-scan base-package="... .dao" />
<context:component-scan base-package="... .service" />
<import resource="data.xml" />
<import resource="security.xml" />
mvc-dispatcher-servlet.xml
<mvc:annotation-driven />
<mvc:resources mapping="/resources/**" location="/resources/" />
<bean
class="org.springframework.web.servlet.view.InternalResourceViewResolver">
<property name="prefix">
<value>/pages/</value>
</property>
<property name="suffix">
<value>.jsp</value>
</property>
</bean>
<bean id="messageSource"
class="org.springframework.context.support.ReloadableResourceBundleMessageSource">
<property name="basename" value="classpath:messages" />
<property name="defaultEncoding" value="UTF-8" />
</bean>
<mvc:interceptors>
<bean class="org.springframework.web.servlet.i18n.LocaleChangeInterceptor">
<property name="paramName" value="sitelocale" />
</bean>
</mvc:interceptors>
<bean id="localeResolver"
class="org.springframework.web.servlet.i18n.CookieLocaleResolver">
<property name="defaultLocale" value="en" />
</bean>
data.xml
<!-- Transaction Manager -->
<bean id="transactionManager"
class="org.springframework.orm.hibernate3.HibernateTransactionManager">
<property name="sessionFactory" ref="sessionFactory" />
</bean>
<bean id="propertyConfigurer"
class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer"
p:location="/WEB-INF/jdbc.properties" />
<!-- //////////////////////////////////////////////////////////////////////////
" -->
<bean id="dataSource" class="com.mchange.v2.c3p0.ComboPooledDataSource"
destroy-method="close">
<property name="driverClass" value="${jdbc.driverClassName}" />
<property name="jdbcUrl" value="${jdbc.databaseurl}" />
<property name="user" value="${jdbc.username}" />
<property name="password" value="${jdbc.password}" />
</bean>
<!-- ////////////////////////////////////////////////////////////////////////// -->
<!-- Hibernate SessionFactory configuration -->
<bean id="sessionFactory"
class="org.springframework.orm.hibernate3.annotation.AnnotationSessionFactoryBean">
<property name="dataSource" ref="dataSource" />
<property name="packagesToScan" value="com.tsystems.javaschool.kts.domain" />
<property name="configurationClass">
<value>org.hibernate.cfg.AnnotationConfiguration</value>
</property>
<property name="hibernateProperties">
<props>
<prop key="hibernate.show_sql">true</prop>
<prop key="hibernate.dialect">${jdbc.dialect}</prop>
<prop key="hibernate.connection.charSet">UTF-8</prop>
</props>
</property>
</bean>
web.xml
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>
/WEB-INF/spring/root-context.xml
</param-value>
</context-param>
<listener>
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>
<!-- Spring MVC -->
<servlet>
<servlet-name>appServlet</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
<init-param>
<param-name>contextConfigLocation</param-name>
<param-value>/WEB-INF/spring/appServlet/mvc-dispatcher-servlet.xml</param-value>
</init-param>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>appServlet</servlet-name>
<url-pattern>/</url-pattern>
</servlet-mapping>
<servlet-mapping>
<servlet-name>default</servlet-name>
<url-pattern>*.js</url-pattern>
</servlet-mapping>
<servlet-mapping>
<servlet-name>default</servlet-name>
<url-pattern>*.css</url-pattern>
</servlet-mapping>
<!-- Spring Security -->
<filter>
<filter-name>springSecurityFilterChain</filter-name>
<filter-class>org.springframework.web.filter.DelegatingFilterProxy</filter-class>
</filter>
<filter-mapping>
<filter-name>springSecurityFilterChain</filter-name>
<url-pattern>*</url-pattern>
</filter-mapping>
You don't need to prefix the basename value with "classpath:", try to change it as follows:
<property name="basename" value="messages" />
Adding the following should allow you to change the lang with a URL parameter named "lang" (i.e. lang=en). This will allow you to override browser default settings and explicitly declare the language in use.
<bean id="localeChangeInterceptor" class="org.springframework.web.servlet.i18n.LocaleChangeInterceptor">
<property name="paramName" value="lang" />
</bean>
<bean id="handlerMapping" class="org.springframework.web.servlet.mvc.annotation.DefaultAnnotationHandlerMapping">
<property name="interceptors">
<ref bean="localeChangeInterceptor" />
</property>
</bean>
Also, ensure in the deployed webapp that the message files are located under WEB-INF/classes/ if you are going to use classpath:messages as a basename.
Also check if you add this at the top
<%# page contentType="text/html;charset=UTF-8" %>