3

プライベート コンストラクターを持つ 4 つのシングルトン クラスがあり、4 つのクラスすべての Bean プロパティを作成しようとしています。

主な問題は、3 つのクラスの Bean を作成でき、これらの 3 つのクラスは getInstance メソッドとプライベート コンストラクター() (Singleton クラス) を備えた同様の構造を持っていますが、4 つ目と最後の 1 つが例外をスローしていることです (Exceptionメッセージは下に貼り付けます)

getInstance メソッド、プライベート コンストラクター、および Bean id 宣言の下にあることを確認してください。これは、4 つの Bean 宣言すべてで同じです

しかし、コンストラクターを「プライベート」から「パブリック」に変更すると、エラーは発生しません。何が起こっているのか、誰かに光を当てることができますか? 他の 3 つのクラスにはプライベート コンストラクターがあり、完全に正常に動作するため

getInstance() メソッド

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;
    }

プライベート コンストラクター

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

Bean プロパティ宣言

<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" />

上記3作品

この Bean プロパティはエラーをスローしています

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

例外メッセージ

[#|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)
:
4

1 に答える 1

8

問題は Bean の作成自体ではありません (既にお気づきのように、それは他の Bean と変わりません)。この問題は、使用しようとしている AOP 構成に関連しているようです。そのクラスのプロキシを作成する場合、クラスをサブクラス化できないため (プライベート コンストラクターがあるため)、CGLIB では作成できません。

これを回避する唯一の方法 (現在の設計を考えると) は、ApplicationConfiguration クラスによって実装されるインターフェイスを作成し、クラスをプロキシする代わりにそのインターフェイスのプロキシを作成することです。

于 2012-08-07T13:58:45.163 に答える