誰もがこのBeanが何回もインスタンス化されている理由を知っていますか?私は1つのインスタンスしか必要としませんが、コントローラが実行されるたびに、コンストラクタが再度呼び出されます。Spring MVCで複数回インスタンス化されたシングルトンBean?
ここで私はそれを使用していますどこapplicationContext.xmlを
<bean id="DiameterClient" class="com.rory.diameter.client.DiameterClient" scope="singleton" init-method="start">
<constructor-arg type="java.lang.String" index="0"><value>${pcca.host}</value></constructor-arg>
<constructor-arg index="1"><value>${pcca.port}</value></constructor-arg>
<constructor-arg index="2" value="com.openwave.djgx.message"/>
<constructor-arg index="3" value="com.openwave.djgx.avp"/>
</bean>
そして、ここに私のコントローラ内で定義されている - これが唯一のDiameterClientクラスのインスタンスを1つになるだろうけれども、私は、それが呼んでいます - そのコンストラクタのコードは以下の実行されるたびに任意のヘルプははるかに高く評価されています
BeanFactory factory = new ClassPathXmlApplicationContext("applicationContext.xml");
DiameterClient diameterClient = (DiameterClient)factory.getBean("DiameterClient");
diameterClient.send(aar);
注意、DiameterClientは私のクラスではない、と私はそれを編集したいいけない、ちょうどアプリケーションごとに、それの一つのグローバルインスタンスを持っていると思います。また、DiameterClientはスレッドを拡張することに注意してください。これが重要かどうかはわかりません。
ありがとうございます。 – Rory