Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9208901
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T00:43:04+00:00 2026-06-18T00:43:04+00:00

I have a Java SE application running an embedded Jetty web server hosting a

  • 0

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

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'

In the Java SE part the first thing I do is to create the application context.

ApplicationContext context = new ClassPathXmlApplicationContext("classpath:server-context.xml","classpath:application-context.xml");

In the web application Spring is configured in web.xml:

<servlet>
    <servlet-name>Jersey REST Service</servlet-name>
    <servlet-class>com.sun.jersey.spi.spring.container.servlet.SpringServlet</servlet-class>
    <init-param>
        <param-name>com.sun.jersey.spi.container.ResourceFilters</param-name>
        <param-value>example.restful.server.filter.SecurityFilterFactory</param-value>
    </init-param>
    <init-param>
        <param-name>com.sun.jersey.config.property.resourceConfigClass</param-name>
        <param-value>com.sun.jersey.api.core.PackagesResourceConfig</param-value>
    </init-param>
    <init-param>
        <param-name>com.sun.jersey.config.property.packages</param-name>
        <param-value>example.restful.rest</param-value>
    </init-param>
    <load-on-startup>1</load-on-startup>
</servlet>
<context-param>
    <param-name>contextConfigLocation</param-name>
    <param-value>classpath:application-context.xml</param-value>
</context-param>
<listener>
    <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>

How can I make the web application use the application context already created instead of duplicating all the beans?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-18T00:43:05+00:00Added an answer on June 18, 2026 at 12:43 am

    I think you can create your own ContextLoaderListener and overriding createWebApplicationContext to return the ApplicationContext of your JavaSE app (assuming you have some kind of ApplicationContextHolder to keep a static access to it).

    It seems easy, but you need to return a WebApplicationContext and not a ClassPathXmlApplicationContext to do this, I think you can do something like this:

    public class MyContextLoaderListener extends ContextLoaderListener{
        protected WebApplicationContext createWebApplicationContext(ServletContext sc,
                                                            ApplicationContext parent){
            ApplicationContext javaSEAppContext = AppContextHolder.getAppContext();
            GenericWebApplicationContext context = new GenericWebApplicationContext(servletContext);
            context.setParent(javaSEAppContext);
            return context;
        }
    }
    

    And of course adapt your web.xml

        <!-- <context-param>
            <param-name>contextConfigLocation</param-name>
            <param-value>classpath:application-context.xml</param-value>
        </context-param> -->
        <listener>
            <listener-class>com.company.MyContextLoaderListener</listener-class>
        </listener>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have an existing Java web application running on Linux using embedded Jetty. The
We have a Java EE-based web application running on a Glassfish app server cluster.
I have a Java web application running on Tomcat. I want to load static
Say, I have a Java application running, and I have provided RESTful web services
I have Java Spring application running in a jetty-maven plugin. When I call a
We have a java application which run as server running on a remote windows
We have inherited an application (Java-based, running on WebLogic 10.3.5) that makes extensive use
We have a Web Java based application running on JBoss with allowed maximum heap
I have an Java application running on a Weblogic Server and Connecting to Oracle
We have a Java web application running on Apache that calls Perl scripts in

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.