は、我々は、実行時にアクセスしたいTomcatエンジンでいくつかの情報があるので、我々は我々のアプリのコンテキストで、次のしている(this blog postからこれを得た):コントローラでプロキシをサービスにどのように注入しますか?
<bean id="tomcatEngineProxy" class="org.springframework.jmx.access.MBeanProxyFactoryBean">
<property name="objectName" value="Catalina:type=Engine" />
<property name="proxyInterface" value="org.apache.catalina.Engine" />
<property name="useStrictCasing" value="false" />
</bean>
、我々はその後でそれをautowiredこのように:そのクラスは、ビルド時に私たちには使用できないため、
@Autowired
private MBeanProxyFactoryBean tomcatEngineProxy = null;
我々は、ブログの記事のようにorg.apache.catalina.Engine
に配線することはできません。これは実行時に、異なるマシン上で実行されているすべての異なるTomcatバージョンでのみ利用可能です。
この@Autowireから必要な情報をリフレクションを使用して取得できました。今、この機能をサービスに移行したいと考えています。
<bean id="myService" class="com.foo.bar.MyServiceImpl">
<constructor-arg ref="tomcatEngineProxy" />
</bean>
とクラスは次のようになります:私は、我々のアプリのコンテキストにこれを追加基本的には何も知らない
org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'myService' defined in ServletContext resource [/WEB-INF/spring/root-context.xml]: Unsatisfied dependency expressed through constructor argument with index 0 of type [org.springframework.jmx.access.MBeanProxyFactoryBean]: Could not convert constructor argument value of type [$Proxy44] to required type [org.springframework.jmx.access.MBeanProxyFactoryBean]: Failed to convert value of type '$Proxy44 implementing org.apache.catalina.Engine,org.springframework.aop.SpringProxy,org.springframework.aop.framework.Advised' to required type 'org.springframework.jmx.access.MBeanProxyFactoryBean'; nested exception is java.lang.IllegalStateException: Cannot convert value of type [$Proxy44 implementing org.apache.catalina.Engine,org.springframework.aop.SpringProxy,org.springframework.aop.framework.Advised] to required type [org.springframework.jmx.access.MBeanProxyFactoryBean]: no matching editors or conversion strategy found
:
public class MyServiceImpl implements MyService
{
public MyServiceImpl(MBeanProxyFactoryBean tomcatEngineProxy) throws Exception
{
//stuff with the proxy
}
.....
}
私はこれを行うと、私は次のエラーを取得しますどのようにプロキシが動作し、どのようにそれらを使用するかについて、私はこの作業を行う方法についてはわかりません。私のコンストラクタ引数に使用できるいくつかの宣言がありますか?コントローラを動作させる@Autowireと、動作しないコンストラクタargとの違いは何ですか?
パーフェクト!魅力のように働いた。私は前にその構文を見ていない。 ' 'ですが、これはXMLを幸せにするための問題です。ありがとう! –
dnc253
np。私はそれが壊れているようにEL式でそれを試してみません:)私はそれのために春にバグがあります。 – Matt