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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T07:24:30+00:00 2026-06-09T07:24:30+00:00

I have 4 singleton classes with private constructors and I’m trying to create bean

  • 0

I have 4 singleton classes with private constructors
and I’m trying to create bean property for all the 4 classes.

The main problem is, I’m able to create the bean for 3 classes
and these 3 classes have similar structure with a getInstance method and
a private constructor() (Singleton class) but the fourth and the last one
is throwing an exception (Exception message is pasted below)

Please find below the getInstance method, the private constructor
and the bean id declaration. Which is same across all the four bean declarations

But If I change the constructor from “Private” to “Public” then
I dont get the error. Could anyone throw any light on what is happening? Since the other three classes have private constructors and they work perfectly fine

The getInstance() method

public static ApplicationConfiguration getInstance() throws IOException,
            IllegalArgumentException, InconsistentDataException {
        ApplicationConfiguration result = instance.get();
        if (result == null) {
            try {
                // Check again if already created
                result = instance.get();
                if (result == null) {
                    result = new ApplicationConfiguration();

                }
            } finally {
                // something here
            }
        } 
        return result;
    }

The private constructor

private ApplicationConfiguration() throws Exception {
        // call a method here
    }

The bean property declaration

<bean id="configManager" class="com.manager.ApplicationConfiguration" factory-method="getInstance" />

<bean id="configEnricher" class="com.enricher.ApplicationConfiguration" factory-method="getInstance" />

<bean id="configBussiness" class="com.validationservice.ApplicationConfiguration" factory-method="getInstance" />

The above three works

This bean property is throwing the error

<bean id="configEviction" class="com.evictionservice.ApplicationConfiguration" factory-method="getInstance" />

The Exception message

[#|2012-08-07 11:53:21,130|ERROR|RMI TCP Connection(226)-172.18.36.14|org.springframework.
web.context.ContextLoader||slodev-rhngp5.mblox.com|core-1|Context initialization failed|#]
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'co
nfigEviction' defined in ServletContext resource [/WEB-INF/camel-context.xml]: Initializat
ion of bean failed; nested exception is org.springframework.aop.framework.AopConfigExcepti
on: Could not generate CGLIB subclass of class [class com.evictionservice.ApplicationConfiguration]: 
Common causes of this problem include using
a final class or a non-visible class; nested exception is java.lang.IllegalArgumentExcepti
on: No visible constructors in class com.evictionservice.ApplicationConfiguration
        at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.do
CreateBean(AbstractAutowireCapableBeanFactory.java:526)
        at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.cr
eateBean(AbstractAutowireCapableBeanFactory.java:455)
        at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(Abstr
actBeanFactory.java:293)
        at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingl
eton(DefaultSingletonBeanRegistry.java:222)
        at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(Abstrac
tBeanFactory.java:290)
        at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractB
eanFactory.java:192)
        at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstant
iateSingletons(DefaultListableBeanFactory.java:585)
        at org.springframework.context.support.AbstractApplicationContext.finishBeanFactor
yInitialization(AbstractApplicationContext.java:895)
        at org.springframework.context.support.AbstractApplicationContext.refresh(Abstract
ApplicationContext.java:425)
:
  • 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-09T07:24:32+00:00Added an answer on June 9, 2026 at 7:24 am

    The problem is not the bean creation itself (as you already noticed, that’s not different from the other beans). The issue seems to be related to some AOP configuration that you’re trying to use. If you want to create a proxy for that class, it cannot do it with CGLIB because the class cannot be subclassed (since it has a private constructor).

    The only way to get around this (given your current design) is to create an interface that will be implemented by the ApplicationConfiguration class and then create the proxy for that interface instead of proxy-ing the class.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have two classes: public class Singleton{ private Singleton(){...} private static class InstanceHolder{ private
So I have a few 'Manager' classes, for example GroupManager. All these Managers are
Looking at this article: http://www.galloway.me.uk/tutorials/singleton-classes/ I have implemented a singleton, my question is the
I have a Singleton that is accessed in my class via a static property
Can we have a model class which is singleton in Doctrine? For Singleton classes
I have four classes, let's call S1, S2, S3 and S4. These class are
I have a re-occurring design problem with certain classes which require one-off initialization with
I have the following problem. I have two classes, in this case A and
I'm trying to learn about singleton classes and how they can be used in
I have a set of singleton classes and I want to avoid boilerplate code.

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.