我有一个Singleton bean如下:
@Singleton
@Startup
public class StartUpBean {
private static final Logger logger = LoggerFactory.getLogger(StartUpBean.class.getName());
public StartUpBean(){
logger.info("here");
}
@PostConstruct
public void onStartup(){
logger.info("hello?");
}
}
这是一个名为control的项目,在一个耳朵中引用为EJB模块(我正在使用maven),如下所示:
<project...>
<packaging>ear</packaging>
...
<dependencies>
...
<dependency>
<groupId>com.thenaglecode</groupId>
<artifactId>control</artifactId>
<version>1.0.0.Pre-Alpha</version>
<type>ejb</type>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-ear-plugin</artifactId>
...
<configuration>
<ejbModule>
<groupId>com.thenaglecode</groupId>
<artifactId>control</artifactId>
<bundleFileName>control.jar</bundleFileName>
<bundleDir>/</bundleDir>
</ejbModule>
...
</configuration>
</plugin>
...
</plugins>
</build>
</project>
我可以看到将StartUpBean绑定到它的jndi名称的输出:
20:23:50,217 INFO [org.jboss.as.ejb3.deployment.processors.EjbJndiBindingsDeploymentUnitProcessor] (MSC service thread 1-12) JNDI bindings for session bean named StartUpBean in deployment unit subdeployment "control.jar" of deployment "thenaglecode.ear" are as follows:
java:global/thenaglecode/control/StartUpBean!com.thenaglecode.control.ejb.StartUpBean
java:app/control/StartUpBean!com.thenaglecode.control.ejb.StartUpBean
java:module/StartUpBean!com.thenaglecode.control.ejb.StartUpBean
java:global/thenaglecode/control/StartUpBean
java:app/control/StartUpBean
java:module/StartUpBean
但是代码永远不会进入post构造方法。即使我可以在同一次跑步中成功击中其他断点,也不会击中断点。任何人都知道我错过了什么?我已经看过解决方案与注释有关的其他类似帖子,但就我所读,我的注释是正确的。
编辑: Startup和Singleton都来自javax.ejb包。