首页 \ 问答 \ 不使用@Resource注入WebServiceContext(WebServiceContext is not injected using @Resource)

不使用@Resource注入WebServiceContext(WebServiceContext is not injected using @Resource)

我知道以前曾经问过,但没有一个解决方案适合我。 可能是因为他们大多使用EE兼容的应用程序服务器,这不是我的情况。

我在jetty(通过Eclipse)上运行我的Web服务仅用于开发。 但即使是部署,我也会使用Tomcat 7.因此,无论是开发还是生产, 我都不会使用兼容JavaEE的服务器。

  • 那么仍然可以将WebServiceContext注入我的Web服务吗?

我尝试过以下但是没有用

@WebService
@BindingType(SOAPBinding.SOAP12HTTP_BINDING)
public class IxProIntegration {
    // Tried this, didn't work
    @Resource
    private WebServiceContext wsContext;

    // After commenting the @Resource annotation on the wsContext field
    // And adding the annotation here, this still didn't work.
    @Resource
    @WebMethod(exclude = true)
    public void setContext(WebServiceContext context) {
        this.wsContext = context;
    }
  • 当有人给出答案时,我很乐意知道他从哪里得到答案?

I know that has been asked before, but none of the solutions worked for me. Probably because they were mostly using EE compliant application servers, which is NOT my case.

I'm running my web service on jetty (through Eclipse) for development only. But even for deployment, I'll use Tomcat 7. So for either development or production, I won't be using a JavaEE compliant server.

  • So is it still possible to inject WebServiceContext into my web services ?

I've tried the following but it didn't work

@WebService
@BindingType(SOAPBinding.SOAP12HTTP_BINDING)
public class IxProIntegration {
    // Tried this, didn't work
    @Resource
    private WebServiceContext wsContext;

    // After commenting the @Resource annotation on the wsContext field
    // And adding the annotation here, this still didn't work.
    @Resource
    @WebMethod(exclude = true)
    public void setContext(WebServiceContext context) {
        this.wsContext = context;
    }
  • When someone kindly gives an answer, I would LOVE to know from where did he get that answer ?

原文:https://stackoverflow.com/questions/18525723
更新时间:2023-11-12 11:11

最满意答案

即使对于一个简单的网站, 选项A中显示的格式也会更好,因为它会从HTML标记中分离出代码。 这也是Unobtrusive JavaScript的主要原则之一。

根据我的经验,使用HTML DOM或类似JQuery的框架替换和修改附加到元素的事件要容易得多,然后在标记中替换多行内联代码。 我工作的大多数网站都有动态生成的内容,使用内联函数维护所有代码会很麻烦。

此外,选项A(将事件附加到元素上)还允许您使用各种功能,如匿名功能和各种类型的闭包 。 在选项B中,需要在div元素之前定义doCalcFunc才能工作。 使用选项A,可以在将函数附加到div的事件时定义该函数。 这使得最初编码和将来维护站点具有更大的灵活性。


Even for a simple website, the format shown in Option A would be better since it seperates the code from the HTML Markup. This is also one of the main principles of Unobtrusive JavaScript.

In my experience it is much easier to replace and modify an event attached to an element using the HTML DOM, or a framework like JQuery, then it is to replace many lines of inline code in markup. Most of the websites I work on have dynamically generated content, and maintaining all of that code using inline functions would be a pain.

In addition, Option A (attaching the event onto an element) also allows you to use a variety of functions, like anonymous functions and various styles of closures. In Option B, doCalcFunc needs to be defined before the div element in order to work. Using Option A, the function can be defined when the function is attached to the div's event. This allows much more flexibility in initially coding, and maintaining the site in the future.

相关问答

更多

相关文章

更多

最新问答

更多
  • 获取MVC 4使用的DisplayMode后缀(Get the DisplayMode Suffix being used by MVC 4)
  • 如何通过引用返回对象?(How is returning an object by reference possible?)
  • 矩阵如何存储在内存中?(How are matrices stored in memory?)
  • 每个请求的Java新会话?(Java New Session For Each Request?)
  • css:浮动div中重叠的标题h1(css: overlapping headlines h1 in floated divs)
  • 无论图像如何,Caffe预测同一类(Caffe predicts same class regardless of image)
  • xcode语法颜色编码解释?(xcode syntax color coding explained?)
  • 在Access 2010 Runtime中使用Office 2000校对工具(Use Office 2000 proofing tools in Access 2010 Runtime)
  • 从单独的Web主机将图像传输到服务器上(Getting images onto server from separate web host)
  • 从旧版本复制文件并保留它们(旧/新版本)(Copy a file from old revision and keep both of them (old / new revision))
  • 西安哪有PLC可控制编程的培训
  • 在Entity Framework中选择基类(Select base class in Entity Framework)
  • 在Android中出现错误“数据集和渲染器应该不为null,并且应该具有相同数量的系列”(Error “Dataset and renderer should be not null and should have the same number of series” in Android)
  • 电脑二级VF有什么用
  • Datamapper Ruby如何添加Hook方法(Datamapper Ruby How to add Hook Method)
  • 金华英语角.
  • 手机软件如何制作
  • 用于Android webview中图像保存的上下文菜单(Context Menu for Image Saving in an Android webview)
  • 注意:未定义的偏移量:PHP(Notice: Undefined offset: PHP)
  • 如何读R中的大数据集[复制](How to read large dataset in R [duplicate])
  • Unity 5 Heighmap与地形宽度/地形长度的分辨率关系?(Unity 5 Heighmap Resolution relationship to terrain width / terrain length?)
  • 如何通知PipedOutputStream线程写入最后一个字节的PipedInputStream线程?(How to notify PipedInputStream thread that PipedOutputStream thread has written last byte?)
  • python的访问器方法有哪些
  • DeviceNetworkInformation:哪个是哪个?(DeviceNetworkInformation: Which is which?)
  • 在Ruby中对组合进行排序(Sorting a combination in Ruby)
  • 网站开发的流程?
  • 使用Zend Framework 2中的JOIN sql检索数据(Retrieve data using JOIN sql in Zend Framework 2)
  • 条带格式类型格式模式编号无法正常工作(Stripes format type format pattern number not working properly)
  • 透明度错误IE11(Transparency bug IE11)
  • linux的基本操作命令。。。