'Singleton and PostConstruct in lib jar not called at startup?
I need to create a little Jar which could be added to other projects (we use maven). This Jar must have a class that is called at startup and must log some basic information. I've been hinted to use Singleton Startup and Postconstruct annotations to do so.
So far I've created my Jar with this class which should log the JRE version :
import javax.annotation.PostConstruct;
import javax.ejb.Singleton;
import javax.ejb.Startup;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@Singleton
@Startup
public class App
{
private final static Logger LOGGER = LoggerFactory.getLogger(App.class);
private AppInfo appInfo;
@PostConstruct
public void init()
{
appInfo = new AppInfo();
String jreVersion = "java not ready";
try {
jreVersion = System.getProperty("java.version");
} catch (final Exception e) {
LOGGER.info("Can't get JRE version");
}
appInfo.setJreVersion(jreVersion);
LOGGER.info("[DiagTest] - The app is running with : " + appInfo.getJreVersion());
}
}
The AppInfo() is just an object with getters/setters.
My problem is when I import my jar in an other project, the init() method seems not to be called, I don't get any error nor any logs.
I think I miss something obvious, but after looking thought multiple post I did not get this to work.
Help would be appreciated,
Thanks.
EDIT: it's working with just a system.out.print, so it seems slf4j is not usable at startup
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
