一个简单的类,实现了ApplicationContextAware 接口,服务启动没用调用setApplicationContext方法
说明: 这个类不打入jar包中就可以调用方法,打进jar包里面之后就没有调用setApplicationContext方法了
下面贴出代码:
java代码:
public class TestAA implements ApplicationContextAware {
@Override
public void setApplicationContext(ApplicationContext arg0)
throws BeansException {
System.out.println("TestAA setApplicationContext......");
}
}
XML配置:
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:jee="http://www.springframework.org/schema/jee"
xmlns:tx="http://www.springframework.org/schema/tx"
xmlns:aop="http://www.springframework.org/schema/aop"
xmlns:context="http://www.springframework.org/schema/context"
xmlns:dubbo="http://code.alibabatech.com/schema/dubbo"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-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/jee
http://www.springframework.org/schema/jee/spring-jee-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/context
http://www.springframework.org/schema/context/spring-context-2.5.xsd
http://code.alibabatech.com/schema/dubbo
http://code.alibabatech.com/schema/dubbo/dubbo.xsd" default-autowire="byName">
<bean id="testAA" class="com.test.TestAA"/>
<bean id="testBB" class="com.test.TestBB"/>
</beans>
TestAA和TestBB除了类名和打印输出不一样外,其他都是一样的。
测试的时候TestAA放在jar包中,TestBB再外面。结果就只调用jar包外面的setApplicationContext方法了,jar包里面的没有调用。
另外,,打jar包使用的是myeclipse打的,勾选了Add directory entries也无法解决此问题。
------解决方案--------------------
你打完jar包,你引用jar包了吗?
------解决方案--------------------
手工打 jar 包呢,试试