Question

I have Tomcat 7.0.47 and I'm hosting a REST Easy JAXRS service. The service uses two external JARs, one that has a base repository interface and default implementation and one that creates a concrete repository derived from the base (i.e. these two JARs have a dependency).

The service works, i.e. I can send a request and get back data from the database.

Now what I'm trying to do is get the repository injected into the REST service, to do this I've changed the REST code to look like

@Path("/country")
public class CountryService {

    @Inject
    ICountriesRepository repository;

    @GET
    @Produces({"application/json", "application/xml"})
    public List<Country> getCountries() throws NamingException, SQLException {
        return repository.getCountries();
    }
}

I've added a beans.xml file to the web application's WAR file (it's in the META-INF directory) and I've added beans.xml to both the JARS.

When I deploy the app I see the following message:

INFO: Adding scanned resource: com.mantiso.cricket.service.CountryService

but I don't see similar messages for the repository class in the JAR.

The JAR is deployed; the beans.xml file is in the JAR's META-INF directory; I've tried adding @ManagedBean to the repository class.

I'm sure I'm missing something simple, but lots of searching has turned up not a lot.

This is Tomcat 7.0.47; Weld 2.1.0; RESTEasy 3.0.5

What else should I try?

Was it helpful?

Solution

And the answer is: The beans.xml file for the web app must be in the WEB-INF directory. If it's in the META-INF directory then it's not parsed.

Although, this did appear to work OK when I tried injecting into a servlet

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top