Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Auto Scanning not finding service classes #657

Open
jmihalich opened this issue Apr 21, 2022 · 0 comments
Open

Auto Scanning not finding service classes #657

jmihalich opened this issue Apr 21, 2022 · 0 comments

Comments

@jmihalich
Copy link

jmihalich commented Apr 21, 2022

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.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.

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

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?

Thanks,
Joe

exception.txt

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant