不使用@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
最满意答案
即使对于一个简单的网站, 选项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 thediv
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.
相关问答
更多-
zzandy的第一个答案应该没问题。 检查你是否正确地做了一切,特别是firefox可以选择确保它处于兼容模式。 这是完整的代码。 ...
-
Javascript:将事件附加到JS中的元素或具有元素调用功能(Javascript: to attach event to element in JS or have element call function)[2022-08-17]
即使对于一个简单的网站, 选项A中显示的格式也会更好,因为它会从HTML标记中分离出代码。 这也是Unobtrusive JavaScript的主要原则之一。 根据我的经验,使用HTML DOM或类似JQuery的框架替换和修改附加到元素的事件要容易得多,然后在标记中替换多行内联代码。 我工作的大多数网站都有动态生成的内容,使用内联函数维护所有代码会很麻烦。 此外,选项A(将事件附加到元素上)还允许您使用各种功能,如匿名功能和各种类型的闭包 。 在选项B中,需要在div元素之前定义doCalcFunc才能工 ... -
我相信你还在使用0.7或更久。 更新到最新版本(撰写本文时为0.8.7), 您将能够执行以下操作 : const Component = Ractive.extend({ template: ` `, foo(){ alert('Hello') }, bar(){ alert('World!') } }); new Component( ...
-
将JavaScript事件处理程序附加到Zend_Form_Element(Attach JavaScript event handler to Zend_Form_Element)[2022-05-26]
尝试使用setAttrib($ name,$ value),例如: $element->setAttrib('onchange', 'jsFunction();'); 您可以在此处找到有关Zend_Form_Element的更多详细信息。 Try with setAttrib($name, $value), for example: $element->setAttrib('onchange', 'jsFunction();'); You can find more detailed informati ... -
使用onpaste事件。 var input = document.getElementById('MyID'); input.onpaste = function () { return false; } use onpaste event. var input = document.getElementById('MyID'); input.onpaste = function () { return false; }
-
使用bind函数定义函数将使用的范围。 目前,您的范围是您的元素,而不是您的类实例。 this.input.addEventListener('focus', this.onFocus_.bind(this)); (function(){ 'use strict'; var Input = function Input(elem) { this.element = elem; this.construct(); }; Input.prototype.Classes = ...
-
请参阅此处了解ko.utils.registerEventHandler 但它看起来也许对ko.components很有用。 See here for ko.utils.registerEventHandler But it also looks like this might be a good use for ko.components.
-
将元素附加到另一个元素后,Jquery双击事件(Jquery double click event after appending element to another element)[2022-07-23]
除去clone函数中的true .clone(); 这不会复制事件处理程序 Remove the true in the clone function .clone(); this will not copy the event handlers -
如果您尝试以这种方式绑定事件: $(element).bind('keydown', function () { alert("hello"); }); jquery将尝试在父window遍历您的元素,但如果您执行以下操作,您的问题将得到解决: $(iframe.contentWindow.document.body).find(element).bind('keydown', function () { alert("hello"); }) ...
-
将'.post_id'替换为'[name = post_id]' replace '.post_id' to '[name=post_id]'