Spring @PostConstruct not working in JBoss7

I am having problems after updating an application that runs on WebSphere and Netweaver to run on JBoss6.2 EAP.

I found that the spring-installed @Repository (org.springframework.stereotype.Repository) using the init () method annotated with @PostConstruct (javax.annotation.PostConstruct) does not have the init () method run when deployed in JBossEAP 6.2. 0.

The class looks something like this:

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; } } 

What I see from the log is that logging in the init method is not logged, and the value of testInitInvoked boolean remains false when the class is used by the application (a good amount of time after startup).

The class above is in the bank nested in war / WEB-INF / lib.

From the spring log, you can see that the UserRoleDao class is automatically set to the class referenced by @Autowired annotation.

Spring buckets are installed in JBoss on JBOSS_HOME \ modules \ com \ company \ thirdparty \ main and they are referenced by the module.xml file correctly (since most spring applications, I know that they refer correctly).

The spring context uses class scanning, as shown in the following snippet of the context xml spring file:

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

So, it’s strange that spring is able to auto-sequence the UserRoleDao class to the Service class that uses it, but @PostConstruct seems to be ignored.

I tried to move the spring banners to the WEB-INF \ lib directory (I found with previous problems in Hibernate that the annotations were not checked if the bans were specified in the JBOSS_HOME \ modules and moved them to WEB -INF \ lib this was fixed).

Has anyone else noticed a similar problem before? (and found a solution!)

The init @PostConstruct method runs when deployed to WebSphere and Netweaver using the same spring versions.

Sorry if I placed this in the wrong place, let me know and I will translate it.

Thanks,

Versions:

JBoss: EAP 6.2.0.GA (built on AS 7.3.0)

Spring: 3.1.1

+6
source share
2 answers

Thanks to the proposal of M. Deinum, I was able to solve this problem. I had to place spring banners in my WEB-INF / lib directory and remove them from the modules directory.

+2
source

Add dependency

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

for module spring works for me.

+2
source

All Articles