class Proxy{
private Class<?> customType;
..
}
interface Foo{
public String foo();
..
}
<bean id="foo" class="com.test.Proxy">
<property name="customType" value="com.test.Foo"/>
</bean>
除了
Bean foo是的实例com.test.Foo
,不是com.test.Proxy
问题
我应该在Proxy类中怎么做,似乎春天提供了与此相关的接口,但我真的不知道该如何实现?
我也通过google搜索,但是找不到,也许我使用的关键字是错误的,任何人都可以帮忙或提供指南链接给我,非常感谢。
结果
class Proxy<T> implements FactoryBean<T>{
private Class<?> customType;
public Class<?> getObjectType() {
return customType;
}
public T getObject() throws Exception {
return (T)customObj;
}
..
}
您必须提供Foo的实现,因为您必须实例化实现而不是接口:
class Proxy{
private Foo customType;
..
}
interface Foo{
public String foo();
..
}
class FooImpl implements Foo{
public String foo();
...
}
然后在xml中,将其设置如下:
<bean id="foo" class="com.test.Proxy">
<property name="customType">
<bean class="com.test.FooImpl" />
</property>
</bean>
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句