我有这样一个方法
package mytest;
public class TestImpl extends AbstractTest implements TestIfc{public void handler() { // TODO Auto-generated method stub } @Override public void test() { // TODO Auto-generated method stub }
}
public abstract class AbstractTest {public abstract void test();
}
public interface TestIfc {public void hander();
}
spring配置文件
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:context="http://www.springframework.org/schema/context"
xmlns:tx="http://www.springframework.org/schema/tx"
xmlns:aop="http://www.springframework.org/schema/aop"
xmlns:jee="http://www.springframework.org/schema/jee"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.5.xsd
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-2.5.xsd
http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-2.5.xsd
http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-2.5.xsd
http://www.springframework.org/schema/jee http://www.springframework.org/schema/jee/spring-jee-2.5.xsd
"><bean id="test" class="mytest.TestImpl" >
</beans>
我如何实例化bean test
来调用方法 test()
谢谢
问题补充:
谢谢各位。
问题补充
我使用
ClassPathXmlApplicationContext c = new ClassPathXmlApplicationContext("application.xml");TestImpl test = (TestImpl)c.getBean(test);
会有 java.lang.ClassCastException
spring默认使用的是jdk的动态代理 ,必须要以下操作才可以TestIfc test = (TestIfc)c.getBean(test);
使用这个获取到bean不会有问题,但这样我就无法调用 方法 test() 了。