You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
First my set up is: Java 17, Jetty 11, and Jersey 3.0.4, and jersey-hk2. This is about as bare bones of a setup as you can get right now. My project has 2 classes in it, a resource class that injects a service class, and the service class itself. No other DI frameworks (like spring or guice).
I'm not able to get auto scanning working in the latest jersey-hk2. The code is not finding my @service class, and thus the Injection code is failing to find an instance of the class.
I added the following dependency to my maven pom file:
org.glassfish.hk2
hk2-metadata-generator
3.0.3
That generates the META-INF/hk2-locator/default file with the correct class name and path in it. However, in the .war file that file is not in the root /META-INF folder. it winds up in /WEB-INF/classes/META-INF folder. I don't know if that is the correct location or not. I tried manually putting the hk2-locator/default in the root META-INF folder but that had no effect.
Anyway, in my Jersey resource class where i Inject the service class, the container cannot find an instance of it...meaning nothing ever scanned and/or found the class to create it.
@service
public class TestService implements PostConstruct, PreDestroy
{
private static final Logger LOGGER = LoggerFactory.getLogger(TestService.class);
public TestService()
{
}
public String getValue()
{
return "got value";
}
public void postConstruct()
{
LOGGER.info("postConstruct");
}
public void preDestroy()
{
LOGGER.info("preDestroy:");
}
}
`
The full stack trace when the injection fails is attached.
Am I doing something wrong? Or am I missing something?
Hi,
First my set up is: Java 17, Jetty 11, and Jersey 3.0.4, and jersey-hk2. This is about as bare bones of a setup as you can get right now. My project has 2 classes in it, a resource class that injects a service class, and the service class itself. No other DI frameworks (like spring or guice).
I'm not able to get auto scanning working in the latest jersey-hk2. The code is not finding my @service class, and thus the Injection code is failing to find an instance of the class.
I added the following dependency to my maven pom file:
org.glassfish.hk2 hk2-metadata-generator 3.0.3That generates the META-INF/hk2-locator/default file with the correct class name and path in it. However, in the .war file that file is not in the root /META-INF folder. it winds up in /WEB-INF/classes/META-INF folder. I don't know if that is the correct location or not. I tried manually putting the hk2-locator/default in the root META-INF folder but that had no effect.
Anyway, in my Jersey resource class where i Inject the service class, the container cannot find an instance of it...meaning nothing ever scanned and/or found the class to create it.
TestService class:
`TestService class:
import org.jvnet.hk2.annotations.Service;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@service
public class TestService implements PostConstruct, PreDestroy
{
private static final Logger LOGGER = LoggerFactory.getLogger(TestService.class);
}
`
The full stack trace when the injection fails is attached.
Am I doing something wrong? Or am I missing something?
Thanks,
Joe
exception.txt
The text was updated successfully, but these errors were encountered: