org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean is failing after upgrading spring–orm jar to 4.1.6 - spring-4

Initially in our project we were using spring 3 + hibernate 3
Recently it has been decided to upgrade 3rd party jars, as part of that spring upgraded to 4 but not hibernate (still hibernate 3 is maintained).
Now we have not changed any code for spring 4 upgrade and when we execute project LocalContainerEntityManagerFactoryBean injection is failing. I have given context file declaration & error stack trace in below. Now the question is how can I make existing project work on spring 4 with out upgrading hibernate.
With Spring ORM 4.1.6 LocalContainerEntityManagerFactoryBean is trying to load JPA 2.0 specific hibernate imports (that is hibernate 4 jar classes) and failing.
<bean id="entityManagerFactory"
class="org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean">
<property name="persistenceXmlLocation" value="classpath:META-INF/persistence.xml"/>
<property name="persistenceUnitName" value="casp-portal"/>
</bean>
<!-- Transaction manager for a single JPA EntityManagerFactory (alternative to JTA -->
<bean id="transactionManager" class="org.springframework.orm.jpa.JpaTransactionManager">
<property name="entityManagerFactory" ref="entityManagerFactory"/>
</bean>
<!-- enable the configuration of transactional behavior based on annotations -->
<tx:annotation-driven transaction-manager="transactionManager"/>
<bean class="org.springframework.orm.jpa.support.PersistenceAnnotationBeanPostProcessor" />
Error Stack trace
Caused by: org.springframework.beans.factory.BeanCreationException:
Error creating bean with name 'entityManagerFactory' defined in class
path resource [applicationContext-securityEJB-DBtest.xml]:
Post-processing failed of bean type [class
org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean]
failed; nested exception is java.lang.IllegalStateException: Failed to
introspect bean class
[org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean]
for persistence metadata: could not find class that it depends on at
org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.applyMergedBeanDefinitionPostProcessors(AbstractAutowireCapableBeanFactory.java:936)
at
org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:512)
at
org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:476)
at
org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:303)
at
org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:230)
at
org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:299)
at
org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:194)
at
org.springframework.context.support.AbstractApplicationContext.getBean(AbstractApplicationContext.java:956)
at
org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:747)
at
org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:480)
at
org.springframework.context.support.ClassPathXmlApplicationContext.(ClassPathXmlApplicationContext.java:139)
at
org.springframework.context.support.ClassPathXmlApplicationContext.(ClassPathXmlApplicationContext.java:93)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at
sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
at
sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:606) at
org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:44)
at
org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:15)
at
org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:41)
at
org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:20)
at
org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:76)
at
org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:50)
at org.junit.runners.ParentRunner$3.run(ParentRunner.java:193) at
org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:52) at
org.junit.runners.ParentRunner.runChildren(ParentRunner.java:191) at
org.junit.runners.ParentRunner.access$000(ParentRunner.java:42) at
org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:184) ...
11 more Caused by: java.lang.IllegalStateException: Failed to
introspect bean class
[org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean]
for persistence metadata: could not find class that it depends on at
org.springframework.orm.jpa.support.PersistenceAnnotationBeanPostProcessor.findPersistenceMetadata(PersistenceAnnotationBeanPostProcessor.java:396)
at
org.springframework.orm.jpa.support.PersistenceAnnotationBeanPostProcessor.postProcessMergedBeanDefinition(PersistenceAnnotationBeanPostProcessor.java:333)
at
org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.applyMergedBeanDefinitionPostProcessors(AbstractAutowireCapableBeanFactory.java:931)
... 44 more Caused by: java.lang.NoClassDefFoundError:
javax/persistence/ValidationMode at
java.lang.Class.getDeclaredMethods0(Native Method) at
java.lang.Class.privateGetDeclaredMethods(Class.java:2615) at
java.lang.Class.getDeclaredMethods(Class.java:1860) at
org.springframework.orm.jpa.support.PersistenceAnnotationBeanPostProcessor.buildPersistenceMetadata(PersistenceAnnotationBeanPostProcessor.java:420)
at
org.springframework.orm.jpa.support.PersistenceAnnotationBeanPostProcessor.findPersistenceMetadata(PersistenceAnnotationBeanPostProcessor.java:392)
... 46 more Caused by: java.lang.ClassNotFoundException:
javax.persistence.ValidationMode at
java.net.URLClassLoader$1.run(URLClassLoader.java:366) at
java.net.URLClassLoader$1.run(URLClassLoader.java:355) at
java.security.AccessController.doPrivileged(Native Method) at
java.net.URLClassLoader.findClass(URLClassLoader.java:354) at
java.lang.ClassLoader.loadClass(ClassLoader.java:425) at
sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:308) at
java.lang.ClassLoader.loadClass(ClassLoader.java:358) ... 51 more

Technologies used currently in project: Hibernate 3 + with recent tech stack upgrade Spring got changed to 4.1 version. Spring 4.1 is forces to use JPA 2.0, at the same time it does backward support, meaning it gives JPA 1.0 supports, see below description taken from Spring site.
Java EE version 6 or above is now considered the baseline for Spring
Framework 4, with the JPA 2.0 and Servlet 3.0 specifications being of
particular relevance. In order to remain compatible with Google App
Engine and older application servers, it is possible to deploy a
Spring 4 application into a Servlet 2.5 environment. However, Servlet
3.0+ is strongly recommended and a prerequisite in Spring’s test and mock packages for test setups in development environments.
Actual Issue: jUnit test cases are failing during below highlighted bean injection time. LocalContainerEntityManagerFactoryBean which is extending Spring-ORM classes is trying to load JPA 2.0 specific hibernate imports and failing.
<bean id="entityManagerFactory"
class="com.abc.persist.LocalContainerEntityManagerFactoryBean">
<property name="persistenceXmlLocation" value="classpath:META-INF/persistence-security.xml"/>
<property name="persistenceUnitName" value="casp-portal"/>
<property name="jpaPropertyMap">
<map>
<entry key="javax.persistence.sharedCache.mode" value="none" />
</map>
</property>
</bean>
<!-- Transaction manager for a single JPA EntityManagerFactory (alternative to JTA -->
<bean id="transactionManager" class="org.springframework.orm.jpa.JpaTransactionManager">
<property name="entityManagerFactory" ref="entityManagerFactory"/>
</bean>
<!-- enable the configuration of transactional behavior based on annotations -->
<tx:annotation-driven transaction-manager="transactionManager"/>
<bean class="org.springframework.orm.jpa.support.PersistenceAnnotationBeanPostProcessor" />
Solutions:
Option I: Keep the old version of Spring-ORM to make it work as is [This is what we currently doing as a work around].
Option II: Copy 3,4 spring-orm java classes into our project and tweak the spring classes code according to our needs[I am planning to implement this way].
Option III: This is in research, trying to find another alternative way to inject entityManager.

Related

Tomcat 7: BeanInitializazionException with Spring MVC and external property file

I have a web application bulit in Spring MVC that has an external property file.
The external file is defined in application-config.xml as follows:
<bean class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
<property name="locations">
<list>
<!-- file di properties -->
<value>file:/myfolder/myfilename.properties</value>
<value>classpath:environment.properties</value>
</list>
</property>
<property name="ignoreUnresolvablePlaceholders" value="true"/>
</bean>
The file is in /myfolder and is under my C:\ folder, but I need to deploy it (in production environment) on a Linux machine in which the property file path is /myfolder.
This web application runs well in Netbeans IDE (8.2) with local Tomcat 7 instance.
I am trying to run it in Eclipse with same local Tomcat 7 instance but I obtain the following exception:
ERROR ContextLoader:319 - Context initialization failed
org.springframework.beans.factory.BeanInitializationException: Could not load properties; nested exception is java.io.FileNotFoundException: \myfolder\myfilename.properties (Impossible to find the path specified)
I've tried to change the server configuration in Eclipse, but nothing happens. How can I solve this issue?

Spring Integration gateway error channel - no such bean exception

I've configured a spring integration gateway with a service activator backed by a threadpool.
Everything works fine, till I try to add my own error channel.
Spring begins to complain that it cannot find a bean by the name of the error channel.
Here is my xml config:
<int:gateway service-interface="Messaging.SendMessageToDeviceGateWay"
error-channel="send_message_to_device_error_channel"
default-request-channel="send_message_to_device_channel"
id="send_message_to_device_gateway">
</int:gateway>
<int:channel id="send_message_to_device_channel">
<int:queue message-store="redisMessageStore" />
</int:channel>
<bean id="sendMessageToDeviceServiceBeanId" class="Messaging.SendMessageToDeviceService" />
<int:service-activator input-channel="send_message_to_device_channel"
ref="sendMessageToDeviceServiceBeanId" method="send_message">
<int:poller fixed-rate="500" time-unit="MILLISECONDS"
task-executor="send_message_to_device_task_executor" receive-timeout="0" />
</int:service-activator>
<bean id="sendMessageToDeviceErrorHandlerBeanId"
class="Messaging.SendMessageToDeviceErrorHandler" />
<int:service-activator input-channel = "send_message_to_device_error_channel"
ref="sendMessageToDeviceErrorHandlerBeanId" method="handle_error">
</int:service-activator>
The error I am seeing is :
Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'send_message_to_device_gateway': Cannot resolve reference to bean 'send_message_to_device_error_channel' while setting bean property 'errorChannel'; nested exception is org.springframework.beans.factory.NoSuchBeanDefinitionException: No bean named 'send_message_to_device_error_channel' is defined
at org.springframework.beans.factory.support.BeanDefinitionValueResolver.resolveReference(BeanDefinitionValueResolver.java:359)
at org.springframework.beans.factory.support.BeanDefinitionValueResolver.resolveValueIfNecessary(BeanDefinitionValueResolver.java:108)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.applyPropertyValues(AbstractAutowireCapableBeanFactory.java:1469)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean(AbstractAutowireCapableBeanFactory.java:1214)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:537)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:476)
at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:303)
at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:230)
at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:299)
at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:194)
at org.springframework.beans.factory.support.DefaultListableBeanFactory.findAutowireCandidates(DefaultListableBeanFactory.java:1127)
at org.springframework.beans.factory.support.DefaultListableBeanFactory.doResolveDependency(DefaultListableBeanFactory.java:1051)
at org.springframework.beans.factory.support.DefaultListableBeanFactory.resolveDependency(DefaultListableBeanFactory.java:949)
at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor$AutowiredFieldElement.inject(AutowiredAnnotationBeanPostProcessor.java:533)
... 24 more
Caused by: org.springframework.beans.factory.NoSuchBeanDefinitionException: No bean named 'send_message_to_device_error_channel' is defined
at org.springframework.beans.factory.support.DefaultListableBeanFactory.getBeanDefinition(DefaultListableBeanFactory.java:694)
at org.springframework.beans.factory.support.AbstractBeanFactory.getMergedLocalBeanDefinition(AbstractBeanFactory.java:1168)
at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:281)
at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:194)
at org.springframework.beans.factory.support.BeanDefinitionValueResolver.resolveReference(BeanDefinitionValueResolver.java:351)
... 37 more
Why is it looking for a bean by that name?
Thanks in advance,
Richard.
That's correct: any bean must be presented in the application context.
Even if you use a default errorChannel, it is populated to the application context by the Spring Integration infrastructure.
So, you must provide <channel id="send_message_to_device_error_channel"/> anyway.

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

OSGI - Not able to access Application resources loaded in a service bundle

I am using OSGI with Spring MVC,details are as follows
Bundle b1-declares message source as bean. the message resource is success fully autowired in a service in bundleb1.
Entry for Message Source in xml is
<bean id="messageSource" class="org.synyx.messagesource.InitializableMessageSource">
<property name="basename" value="ApplicationResources"/>
<property name="messageProvider">
<bean class="org.synyx.messagesource.jdbc.JdbcMessageProvider">
<property name="dataSource" ref="dataSource"/>
</bean>
</property>
</bean>
Message source is exposed as a service in osgi-context.xml of bundle b1 as follows
<osgi:service interface="org.springframework.context.MessageSource" ref="messageSource"/>
To import the message resources in the WAB bundle, have made following entry in osgi-context.xml of WAB have made following entry to import the messageSource service exposed by bundle b1.
Note - i have not created messageSource bean in WAB(not defined messageSource in *-servlet.xml) as i expect the messageSource to be imported from Bundle B1 and be used by spring for lang resolution.
Problem is -when i hit sample Jsp placed in WAB
i recieve error
javax.servlet.ServletException: javax.servlet.jsp.JspTagException: No message found under code 'user.nametext' for locale 'en_US'.
Analysis- Further debugging the spring code i found that messagesource used in webapplication context is of type DelegatingMessageSource. But the messageSource imported from bundle b1 expose object of type InitializableMessageSource.
This means webapplication context is not initialized with messageSource that is imported through osgi-context.xml of WAB.
PLS help...
In your consumer bundle, add the following to your sping config:
<osgi:reference id="messageSource" interface="org.springframework.context.MessageSource" />
Then, you can inject the messageSource-bean as you would do with a local bean.

Application not working after modify dispatcher-servlet.xml in spring mvc

I'm new to the spring framework. Currently I studying about spring framework. I follow this tutorials,
http://netbeans.org/kb/docs/web/quickstart-webapps-spring.html
http://static.springsource.org/docs/Spring-MVC-step-by-step/part1.html
But I have a problem in both example, after adding beans to dispather-servlet.xml and modify application-contex.xml application is not deploy. It gives following massage.
In-place deployment at C:\Users...\Documents\NetBeansProjects\springapp\build\web
Initializing...
deploy?DEFAULT=C:\Users...\Documents\NetBeansProjects\springapp\build\web&name=springapp&contextroot=/springapp&force=true failed on GlassFish Server 3.1.2
Error occurred during deployment: Exception while loading the app : java.lang.IllegalStateException: ContainerBase.addChild: start: org.apache.catalina.LifecycleException: org.apache.catalina.LifecycleException: java.lang.ClassNotFoundException: springapp.web.HelloController. Please see server.log for more details.
C:\Users...\Documents\NetBeansProjects\springapp\nbproject\build-impl.xml:728: The module has not been deployed.
See the server log for details.
BUILD FAILED (total time: 2 seconds)
Please help to solve this.
Thank you in advance.
PS:-
#shazinltc -
Here is my dispatcher-servlet.xml
<?xml version="1.0" encoding="UTF-8"?>
<bean class="org.springframework.web.servlet.mvc.support.ControllerClassNameHandlerMapping"/>
<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" />
<bean name="indexController"
class="org.springframework.web.servlet.mvc.ParameterizableViewController"
p:viewName="index" />
<bean name="helloService" class="service.HelloService" />
I manage to solve my problem with following tutorial.
https://sites.google.com/site/springmvcnetbeans/step-by-step/
This tutorial is quite simple and more specific and descriptive in each step. I recommend this tutorial for beginners in spring.

Resources