0

次のように、applicationContext で定義された Spring Bean があります。

<bean id="spaceReader" class="com.company.SpaceReader">
</bean>

以下を使用せずに、アプリケーション サーブレットでこの Bean にアクセスできるようにしたいと考えています。

ApplicationContext context = new ClassPathXmlApplicationContext(CONTEXT_LOCATION);
context.getBean("SpaceReader");

以下を使用してエクスポートを試みました。

<bean id="ContextExporter" class="org.springframework.web.context.support.ServletContextAttributeExporter">
    <property name="contextExporterAttributes">
        <map>
            <entry key="SpaceReaderKey">
            <ref local="spaceReader" />
        </entry>
        </map>
    </property>
</bean>

しかし、サーブレットに注入すると、Null 値が返されます。Bean をエクスポートするとき、またはサーブレットでアクセスしようとするときに、何か不足しているのかどうか疑問に思っていますか?

4

1 に答える 1