<bdo id='VKf8J'></bdo><ul id='VKf8J'></ul>

    <small id='VKf8J'></small><noframes id='VKf8J'>

    <i id='VKf8J'><tr id='VKf8J'><dt id='VKf8J'><q id='VKf8J'><span id='VKf8J'><b id='VKf8J'><form id='VKf8J'><ins id='VKf8J'></ins><ul id='VKf8J'></ul><sub id='VKf8J'></sub></form><legend id='VKf8J'></legend><bdo id='VKf8J'><pre id='VKf8J'><center id='VKf8J'></center></pre></bdo></b><th id='VKf8J'></th></span></q></dt></tr></i><div id='VKf8J'><tfoot id='VKf8J'></tfoot><dl id='VKf8J'><fieldset id='VKf8J'></fieldset></dl></div>

    <tfoot id='VKf8J'></tfoot>

        <legend id='VKf8J'><style id='VKf8J'><dir id='VKf8J'><q id='VKf8J'></q></dir></style></legend>

        @Inject 在 Struts 2 的 Jersey REST Web 服务中不起作用

        @Inject not working in Jersey REST webservices in Struts 2(@Inject 在 Struts 2 的 Jersey REST Web 服务中不起作用)

      1. <i id='nGnx2'><tr id='nGnx2'><dt id='nGnx2'><q id='nGnx2'><span id='nGnx2'><b id='nGnx2'><form id='nGnx2'><ins id='nGnx2'></ins><ul id='nGnx2'></ul><sub id='nGnx2'></sub></form><legend id='nGnx2'></legend><bdo id='nGnx2'><pre id='nGnx2'><center id='nGnx2'></center></pre></bdo></b><th id='nGnx2'></th></span></q></dt></tr></i><div id='nGnx2'><tfoot id='nGnx2'></tfoot><dl id='nGnx2'><fieldset id='nGnx2'></fieldset></dl></div>
        <legend id='nGnx2'><style id='nGnx2'><dir id='nGnx2'><q id='nGnx2'></q></dir></style></legend>
              <bdo id='nGnx2'></bdo><ul id='nGnx2'></ul>

              1. <small id='nGnx2'></small><noframes id='nGnx2'>

                • <tfoot id='nGnx2'></tfoot>
                    <tbody id='nGnx2'></tbody>
                • 本文介绍了@Inject 在 Struts 2 的 Jersey REST Web 服务中不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  我创建了一个用于测试 Struts 2 依赖注入 (@Inject) 的应用程序.除了我在其中定义了 Web 服务操作的 Jersey REST 服务类之外,注入在许多领域都运行良好.

                  I have created an application for testing the Struts 2 dependency injection (@Inject). The injection is working fine in many areas except Jersey REST service class within which I have defined the webservices actions.

                  我得到如下所示的异常:

                  I am getting exception like as shown below:

                  Sep 22, 2014 8:48:50 AM com.sun.jersey.spi.container.ContainerResponse mapMappableContainerException
                  SEVERE: The RuntimeException could not be mapped to a response, re-throwing to the HTTP container
                  java.lang.NullPointerException
                      at usermodules.services.UserModulesServices.userName(UserModulesServices.java:30)
                      at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
                      at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
                      at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
                  

                  谁能告诉我一些解决方法?

                  Can anyone please tell me some solution for this?

                  struts.xml:

                  <?xml version="1.0" encoding="UTF-8" ?>
                  <!DOCTYPE struts PUBLIC
                      "-//Apache Software Foundation//DTD Struts Configuration 2.0//EN"
                      "http://struts.apache.org/dtds/struts-2.0.dtd">
                   
                  <struts>
                  <bean class="net.viralpatel.struts2.action.MoreServiceImpl" name="services" />
                  
                    <constant name="struts.action.excludePattern" value="/rest/.*" />
                      <constant name="struts.enable.DynamicMethodInvocation"
                          value="false" />
                      <constant name="struts.devMode" value="false" />
                      <constant name="struts.custom.i18n.resources"
                          value="ApplicationResources" />
                    
                   
                      <package name="default" extends="struts-default" namespace="/">
                          <action name="login"
                              class="net.viralpatel.struts2.action.LoginAction">
                              <result name="success">Welcome.jsp</result>
                              <result name="error">Login.jsp</result>
                          </action>
                      </package>
                  </struts>
                  

                  UserModulesServices.java:

                  import javax.ws.rs.PathParam;
                  import javax.ws.rs.Produces;
                  import javax.ws.rs.core.MediaType;
                  
                  import net.viralpatel.struts2.action.MoreServiceImpl;
                  
                  import com.opensymphony.xwork2.inject.Inject;
                  
                  @Path("/users")
                  public class UserModulesServices {
                      
                      @Inject("services")
                      public MoreServiceImpl moreServiceImpl;
                  
                      public MoreServiceImpl getMoreServiceImpl() {
                          return moreServiceImpl;
                      }
                  
                      public void setMoreServiceImpl(MoreServiceImpl moreServiceImpl) {
                          this.moreServiceImpl = moreServiceImpl;
                      }
                      
                      @GET
                      @Path("/name/{i}")
                      @Produces(MediaType.TEXT_PLAIN)
                      public String userName(@PathParam("i") String i) {
                          System.out.println("name::::::::" + moreServiceImpl.validate());
                          return "{"name":"" + i + ""}";
                      }
                  }
                  

                  MoreServiceImpl.java:

                  package net.viralpatel.struts2.action;
                  
                  public class MoreServiceImpl implements MoreServices{
                  
                      @Override
                      public String validate() {
                          return "testing";
                      }
                  
                  }
                  

                  推荐答案

                  来自官方 CDI 插件文档:

                  使用正确的@Inject

                  Struts 2 和它的核心组件 XWork 使用它自己的内部依赖注入容器.有趣的是,你可以命名它JSR-330 的祖母,因为它是 Google 的早期预发布版本Guice 曾经由 Crazybob Lee 开发 - 同一个 Bob Lee,一起与 SpringSource 的 Rod Johnson 一起领导 JSR-330 规范.

                  Struts 2 and it's core component XWork use it's own internal dependency injection container. Interestingly, you could name it JSR-330's grandma, since it is an early pre-release version of Google Guice once developed by Crazybob Lee - the same Bob Lee that, together with SpringSource's Rod Johnson, lead the JSR-330 specification.

                  也就是说,你会发现 @Inject 注释都是com.opensymphony.xwork2.inject.Injectjavax.inject.Inject.不要混合这两个 - javax.inject.Inject 是您要使用的那个您的 Struts 2 CDI 插件和一般的 CDI 集成!当你也可以使用 Struts 的内部注解,效果可能是undefined 很奇怪 - 所以检查你的导入!

                  That said, you will find the @Inject annotation both as com.opensymphony.xwork2.inject.Inject and javax.inject.Inject. Don't mix up those two - javax.inject.Inject is the one you want to use with your Struts 2 CDI plugin and CDI integration in general! While you could use Struts' internal annotation as well, the effect may be strange to undefined - so check your imports!

                  然后使用正确的 com.opensymphony.xwork2.inject.Inject
                  代替 javax.inject.Inject

                  这篇关于@Inject 在 Struts 2 的 Jersey REST Web 服务中不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  本站部分内容来源互联网,如果有图片或者内容侵犯了您的权益,请联系我们,我们会在确认后第一时间进行删除!

                  相关文档推荐

                  Java Bytecode Manipulation Library Suggestions(Java 字节码操作库建议)
                  Java CLI UI-design: frameworks or libraries?(Java CLI UI 设计:框架还是库?)
                  About the use of Beans.xml configuration file in Spring Framework application(关于Spring Framework应用中Beans.xml配置文件的使用)
                  What is the difference between Spring, Struts, Hibernate, JavaServer Faces, Tapestry?(Spring、Struts、Hibernate、JavaServer Faces、Tapestry 有什么区别?)
                  Are there any android application framework like spring?(有没有像spring这样的android应用程序框架?)
                  Java Swing based game framework. Any advice?(基于 Java Swing 的游戏框架.有什么建议吗?)
                  • <bdo id='L0f65'></bdo><ul id='L0f65'></ul>
                    <i id='L0f65'><tr id='L0f65'><dt id='L0f65'><q id='L0f65'><span id='L0f65'><b id='L0f65'><form id='L0f65'><ins id='L0f65'></ins><ul id='L0f65'></ul><sub id='L0f65'></sub></form><legend id='L0f65'></legend><bdo id='L0f65'><pre id='L0f65'><center id='L0f65'></center></pre></bdo></b><th id='L0f65'></th></span></q></dt></tr></i><div id='L0f65'><tfoot id='L0f65'></tfoot><dl id='L0f65'><fieldset id='L0f65'></fieldset></dl></div>
                    <legend id='L0f65'><style id='L0f65'><dir id='L0f65'><q id='L0f65'></q></dir></style></legend>
                          <tbody id='L0f65'></tbody>

                        1. <tfoot id='L0f65'></tfoot>

                            <small id='L0f65'></small><noframes id='L0f65'>