Announcement Announcement Module
Collapse
No announcement yet.
Application context duplicated Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • Application context duplicated

    I have a Java SE application running a Jetty web server hosting a web application. I want to use Spring dependency injection both in the Jetty configuration and in the web application. Some beans, e.g. a dao and the entity manager, needs to be shared between the two. When I start the application I get duplicate versions of both the beans and the entity manager.

    Spring prints this to the log:
    Code:
    WARN EntityManagerFactoryRegistry.addEntityManagerFactory:80 - HHH000436: Entity manager factory name (persistenceUnit) is already registered.  If entity manager will be clustered or passivated, specify a unique value for property 'hibernate.ejb.entitymanager_factory_name'
    How can I make the web application use the same application context as the rest of the application and not duplicate all the beans?

  • #2
    I fix this issue just created two application context xml files:

    1st. application-context.xml with entityManagerFactory bean. And registers in web.xml
    Code:
    <context-param>
    		<param-name>contextConfigLocation</param-name>
    		<param-value>
                           /WEB-INF/application-context.xml
                     </param-value>
    </context-param>
    2nd. application-context-web.xml without entityManagerFactory bean. And registers in web.xml
    Code:
    <servlet>
    		<servlet-name>controller</servlet-name>
    		<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
    		<init-param>
    			<param-name>contextConfigLocation</param-name>
    			<param-value>
    				/WEB-INF/application-context-web.xml
            	</param-value>
    		</init-param>
    		<load-on-startup>1</load-on-startup>
    </servlet>

    Comment

    Working...
    X