繁体   English   中英

spring @PostConstruct不在JBoss7中触发

[英]spring @PostConstruct not firing in JBoss7

更新在WebSphere和Netweaver中运行的应用程序以在JBoss6.2 EAP中运行后,我遇到了麻烦。

我发现使用@PostConstruct(javax.annotation.PostConstruct)注释的init()方法的Spring管理的@Repository(org.springframework.stereotype.Repository)在JBossEAP中部署时没有运行init()方法6.2.0。

该类看起来如下所示:

        package com.company.productname.api.dao.impl;


        // ... imports removed ....

        @Repository
        public class UserRoleDao extends AbstractBaseDao {

            private static final Log LOG = LogFactory.getLog(UserRoleDao.class);

            private boolean testInitInvoked = false;


            // .... some code removed .... 

            /**
             * Prepare the caches used to lookup market roles
             */
            @PostConstruct
            protected void init() {
             testInitInvoked = true;
            if (LOG.isDebugEnabled())LOG.debug("UserRoleDao.init() method called");

                      // .. . . . some code removed ......
              }


            @Override
            public Mask getMask(final String aMaskName) {
                LOG.debug("getRoleMask entered, testInitInvoked = [" + testInitInvoked + "]- aMaskName = " + aMaskName);

                Mask myMask = masksByName.map().get(aMaskName);

                if (myMask != null) {
                    myMask.setMembers(this.getMembersForMaskId(myMask.getId()));
                }

                LOG.debug("getRoleMask returning - myMask = " + myMask);

                return myMask;
            }
        }

我从日志记录中看到的是,init方法中的日志记录没有被记录,并且当应用程序使用该类时,testInitInvoked布尔值的值保持为false(启动后的一段时间)。

上面的类是一个捆绑在war / WEB-INF / lib中的jar。

我可以从spring日志中看到UserRoleDao类被自动连接到使用@Autowired注释引用它的类中。

弹簧罐安装在JBoss的JBOSS_HOME \\ modules \\ com \\ company \\ thirdparty \\ main中,并由module.xml文件正确引用(因为大多数应用程序是spring管理的,我知道它们被正确引用)。

spring上下文使用类扫描,如以下摘自spring context xml文件所示:

<context:component-scan base-package="com.company.productname.api" />

所以,奇怪的是spring能够将UserRoleDao类自动装入使用它的Service类中,但@PostConstruct似乎被忽略了。

我已经尝试将spring jar移动到WEB-INF \\ lib目录中(我发现以前围绕Hibernate的问题是,如果在JBOSS_HOME \\ modules中引用了jar并将它们移动到WEB-INF \\ lib目录中,那么注释就不会被扫描固定的)。

之前有没有人注意到类似的问题? (并找到了解决方案!)

使用相同的spring版本jar在WebSphere和Netweaver中部署时,会触发@PostConstruct init方法。

如果我在错误的地方发布了这个,请道歉,请告诉我,我会移动它。

谢谢,

版本:

JBoss:EAP 6.2.0.GA(基于AS 7.3.0构建)

春天:3.1.1

添加依赖项

<module name="javax.annotation.api" export="true"/>

弹簧模块适合我。

感谢M. Deinum的建议,我能够解决这个问题。 我必须将spring jar放在我的WEB-INF / lib目录中,然后将它们从modules目录中删除。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM