Tomcat 7,Weld,RESTEasy无法扫描JAR [英] Tomcat 7, Weld, RESTEasy not Scanning JARs

查看:104
本文介绍了Tomcat 7,Weld,RESTEasy无法扫描JAR的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有Tomcat 7.0.47,正在托管REST Easy JAXRS服务.该服务使用两个外部JAR,一个具有基本存储库接口和默认实现,一个创建从基础派生的具体存储库(即,这两个JAR具有依赖性).

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.

现在我要做的是将存储库注入到REST服务中,为此,我将REST代码更改为

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

我已经将bean.xml文件添加到Web应用程序的WAR文件中(位于META-INF目录中),并且已经将bean.xml添加到两个JARS中.

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

但是在JAR中我没有看到关于存储库类的类似消息.

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

JAR已部署; beans.xml文件位于JAR的META-INF目录中;我尝试将@ManagedBean添加到存储库类.

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.

这是Tomcat 7.0.47;焊接2.1.0;重构3.0.5

This is Tomcat 7.0.47; Weld 2.1.0; RESTEasy 3.0.5

我还应该尝试什么?

推荐答案

答案是:Web应用程序的beans.xml文件必须位于WEB-INF目录中.如果它位于META-INF目录中,则不会对其进行解析.

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.

尽管如此,当我尝试注入到servlet中时,这确实可以正常工作

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

这篇关于Tomcat 7,Weld,RESTEasy无法扫描JAR的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆