类实现ApplicationContextAware接口,没有调用setApplicationContext方法

smatiger 2014-02-20 02:17:26
一个简单的类,实现了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也无法解决此问题。
...全文
154 1 打赏 收藏 转发到动态 举报
写回复
用AI写文章
1 条回复
切换为时间正序
请发表友善的回复…
发表回复
smatiger 2014-02-20
  • 打赏
  • 举报
回复
此贴转到java Web开发板块

67,513

社区成员

发帖
与我相关
我的任务
社区描述
J2EE只是Java企业应用。我们需要一个跨J2SE/WEB/EJB的微容器,保护我们的业务核心组件(中间件),以延续它的生命力,而不是依赖J2SE/J2EE版本。
社区管理员
  • Java EE
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧