REST Web服务的javax.inject返回null

时间:2018-10-23 14:33:27

标签: java web-services cdi web.xml inject

我有一个使用以下servlet的web.xml调用的其余Web服务:-

 <servlet>
        <servlet-name>Welcome</servlet-name>
        <servlet-class>org.glassfish.jersey.servlet.ServletContainer</servlet-class>
        <init-param>
            <param-name>jersey.config.server.provider.packages</param-name>
            <param-value>com.amdocs.bda.ccr.rest</param-value>
            <param-name>log4j-properties-location</param-name>
            <param-value>WEB-INF/log4j.properties</param-value>
        </init-param>

        <load-on-startup>1</load-on-startup>
    </servlet>

    <servlet-mapping>
        <servlet-name>Welcome</servlet-name>
        <url-pattern>/*</url-pattern>
    </servlet-mapping>

服务转到以下类,并且get方法称为:-

   @Service
    @Path("/households")
    @Produces(MediaType.APPLICATION_JSON)
    @Consumes(MediaType.APPLICATION_JSON)
    public class HouseholdService extends Application{

        private static final String API = SEARCH_HOUSEHOLD;

        @Inject
        private Provider<CcrBO> ccrBOProvider;

        HashMap map = new HashMap<String, String>();
        final static Logger logger = Logger.getLogger(HouseholdService.class);


        @GET
        public CcrResponse getHouseholdInfo()
    {
 CcrBO bo = ccrBOProvider.get();

    }

问题是get方法返回的“ bo”为空。我知道通过web.xml可以直接调用get方法,并且在我的情况下实际上不会进行注入。理解正确吗?我如何确保发生这种注入并且get方法不会返回null?

0 个答案:

没有答案