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 6957329
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T14:59:14+00:00 2026-05-27T14:59:14+00:00

I’m trying to build an app using Jersey, Rest, Tomcat, c3p0 etc. I have

  • 0

I’m trying to build an app using Jersey, Rest, Tomcat, c3p0 etc.

I have a ConfigurationManager class I want to be an eager singleton, and Connection pool class I also want to be an eager singleton. Connection pool is using a Configuration Manager annotated with inject but configuration manager inside Connection pool is null, it’s not injected for some reason. It’s instantiated by guice I can see this from log.

When I inject it in Rest resource class it is working as expected.

Also when I inject it in StartupServlet it’s null.

I would very much appreciate it if anyone can shed some light on this. Below you can find web.xml and classes.

web.xml

<servlet>
    <servlet-name>StartupServlet</servlet-name>
    <servlet-class>net.nemanjakovacevic.ft1p.configuration.StartupServlet</servlet-class>
    <load-on-startup>1</load-on-startup>
</servlet>

<!-- set up Google Guice Servlet integration -->
<filter>
    <filter-name>guiceFilter</filter-name>
    <filter-class>com.google.inject.servlet.GuiceFilter</filter-class>
</filter>
<filter-mapping>
    <filter-name>guiceFilter</filter-name>
    <url-pattern>/*</url-pattern>
</filter-mapping>
<listener>
    <listener-class>net.nemanjakovacevic.ft1p.configuration.GuiceServletConfiguration</listener-class>
</listener>

GuiceServletConfiguration.java

public class GuiceServletConfiguration extends GuiceServletContextListener {

@Override
protected Injector getInjector() {
    return Guice.createInjector(new GuiceConfigurationModule(),  new JerseyServletModule() {

        @Override
        protected void configureServlets() {

            /* bind the REST resources */
            bind(Test.class);

            serve("/*").with(GuiceContainer.class);
        }

    });
}

}

GuiceConfigurationModule.java

public class GuiceConfigurationModule extends AbstractModule {

@Override
protected void configure() {
    bind(ConfigurationManager.class).asEagerSingleton();
    bind(ConnectionPool.class).asEagerSingleton();
}

}

ConfigurationManager

public class ConfigurationManager {
// Nothing important here, loading from config file
}

ConnectionPool (It’s not working here)

public class ConnectionPool {

private static final Logger log = LoggerFactory.getLogger(ConnectionPool.class);

private ComboPooledDataSource pooledDataSource;

@Inject
private ConfigurationManager cManager;

public ConnectionPool() {
    log.info("Initializing c3p0 coonection pool");
    pooledDataSource = new ComboPooledDataSource();
    try {
//Null pointer exception here, cManager is null
        pooledDataSource.setDriverClass(cManager.getJdbcDriverClassName());
        pooledDataSource.setJdbcUrl(cManager.getJdbcUrl());
        pooledDataSource.setUser(cManager.getDatabaseUsername());
        pooledDataSource.setPassword(cManager.getDatabasePassword());
    } catch (PropertyVetoException e) {
        log.error("Exception during c3p0 initalisation.", e);
        //TODO obrada izuzetaka
    }
}
}

Test.java (It’s working here)

@Path("/test")
public class Test {

@Inject
ConfigurationManager cManager;

@GET
@Path("/{param}")
public Response getMsg(@PathParam("param") String msg){
                    // cManager is not null, it's injected as it should be
        String output = cManager.getDatabaseHostName();
        return Response.status(200).entity(output).build();
}
}
  • 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-05-27T14:59:15+00:00Added an answer on May 27, 2026 at 2:59 pm

    Field ConfigurationManager cManager will be injected when object construction is completed. That’s why you are getting NPE in constructor and everything is fine in Test.java class.

    Consider replacing field injection with constructor injection.

    Just try this code

    public class ConnectionPool {
        @Inject
        public ConnectionPool(ConfigurationManager cManager) {
            ...
        }
    
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

We're building an app, our first using Rails 3, and we're having to build
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I have a French site that I want to parse, but am running into
I have thousands of HTML files to process using Groovy/Java and I need to
I am using Paperclip to handle profile photo uploads in my app. They upload
I am trying to loop through a bunch of documents I have to put
I am trying to understand how to use SyndicationItem to display feed which is
Basically, what I'm trying to create is a page of div tags, each has
I'm new to using the Perl treebuilder module for HTML parsing and can't figure
link Im having trouble converting the html entites into html characters, (&# 8217;) i

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.