禁用弹簧自动装配

发布于 2024-12-20 00:12:21 字数 1832 浏览 2 评论 0原文

我有一个带有 struts2.2 和 spring 3.1 的应用程序,我想禁用 spring 自动装配。 我用谷歌搜索了一下,发现我必须放在 选项卡 default-autowire="no" 上,但这似乎不起作用。

然后我发现我可以为每个 标签声明这一点,如下所示:,但这似乎不起作用任何一个。

当我启用 spring 调试记录器时,我可以看到很多 aof 消息,如下所示:

信息:调试 [http-thread-pool-8080(3)] (ConstructorResolver.java:739) - 通过构造函数按类型从 bean 名称“com.common.actions.PopupAction”自动装配到名为“intermedService”的 bean< /p>

和相应的条目在 applicationConfig.xml 中是:

<beans default-autowire="no" 
       xmlns="http://www.springframework.org/schema/beans"
       xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
       xmlns:p="http://www.springframework.org/schema/p"
       xmlns:tx="http://www.springframework.org/schema/tx"
       xsi:schemaLocation="http://www.springframework.org/schema/beans
       http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
       http://www.springframework.org/schema/tx
       http://www.springframework.org/schema/tx/spring-tx-3.0.xsd">

<bean id="PopupAction" scope="prototype" class="com.common.actions.PopupAction" autowire="no">
        <constructor-arg type="com.common.services.abs.iIntermedService" ref="intermedService"/>
        <constructor-arg type="com.common.services.abs.iLocationService" ref="locationService"/>
        <constructor-arg type="com.common.services.abs.iUserService" ref="userService"/>
        <constructor-arg type="com.common.services.abs.iPhoneService" ref="phoneService"/>
    </bean>

只要我在这里手动定义了依赖项并且我定义了,为什么 spring 会尝试自动装配此操作auto-wire="no"

或者这条消息告诉我,接线是通过构造函数按类型进行的(如我想要的),“按类型自动接线”意味着从 4 个参数中,他按类型将 intermedService 与我的变量 intermed 服务相匹配(而不是按顺序或其他方式) ?

i ahave an app with struts2.2 and spring 3.1 and i want to disable spring autowire.
I googled a little bit and found that i have to put at <beans> tab default-autowire="no", but this doesn't seems to work.

Then i fount that i can declare this for every <bean> tag like this : <bean autowire="no">, but this does not seems to work either.

When i enabled spring debug logger i can see a lot aof messages like this :

INFO: DEBUG [http-thread-pool-8080(3)] (ConstructorResolver.java:739) - Autowiring by type from bean name 'com.common.actions.PopupAction' via constructor to bean named 'intermedService'

and the corresponding entry in applicationConfig.xml is :

<beans default-autowire="no" 
       xmlns="http://www.springframework.org/schema/beans"
       xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
       xmlns:p="http://www.springframework.org/schema/p"
       xmlns:tx="http://www.springframework.org/schema/tx"
       xsi:schemaLocation="http://www.springframework.org/schema/beans
       http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
       http://www.springframework.org/schema/tx
       http://www.springframework.org/schema/tx/spring-tx-3.0.xsd">

<bean id="PopupAction" scope="prototype" class="com.common.actions.PopupAction" autowire="no">
        <constructor-arg type="com.common.services.abs.iIntermedService" ref="intermedService"/>
        <constructor-arg type="com.common.services.abs.iLocationService" ref="locationService"/>
        <constructor-arg type="com.common.services.abs.iUserService" ref="userService"/>
        <constructor-arg type="com.common.services.abs.iPhoneService" ref="phoneService"/>
    </bean>

why does spring trying to autowire this action as long as i defined the dependency by hand here and i defined auto-wire="no"?

Or this message tells me that the wiring was made by type via constructor(as i wanted) and "Autowiring by type" means that from the 4 params he matched intermedService with my variable intermed service by type (and not by order or something else)?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

不必了 2024-12-27 00:12:21

Struts 2 Spring 插件默认将自动装配设置为“name”。目前,我不相信该插件允许“none”作为值,但您可以尝试使用“auto”——我怀疑这不会有帮助,因为它仍然是一个自动装配 bean 工厂。

这一点之前已经提出过;我不记得有任何真正的决议。我再次提出这个问题,看看是否可以在下一个版本中解决这个问题,我们会进行一些重大清理。

编辑还有struts.objectFactory.spring.autoWire.alwaysRespect常量,默认为false;尝试将其设置为true。我不记得布尔值的哪种含义意味着哪种,或者它是否有效果——现在就看看吧。

The Struts 2 Spring plugin sets autowiring to "name" by default. Currently I don't believe the plugin allows "none" as a value, but you could try using "auto"--I suspect this will not help, as it is still an autowiring bean factory.

This has been brought up before; I don't recall any real resolution. I've brought it up again to see if it can be addressed in the next release where we doing some significant cleanup.

Edit There's also the struts.objectFactory.spring.autoWire.alwaysRespect constant which defaults to false; try setting it to true. I don't recall which sense of the boolean means which, or if it has the effect--looking in to it now.

嘿哥们儿 2024-12-27 00:12:21

解决这个问题的一种方法(直到它得到修复)就是以不同的方式命名你的字段/构造函数参数和你的bean,这样 spring 就无法匹配它们。

A way to get around it (until it gets fixed) is to just name your fields/constructor arguments and your beans differently, so that spring can't match them.

傲世九天 2024-12-27 00:12:21

我相信 default-autowire="no" 默认情况下处于启用状态。即,如果不指定 default-autowire,则表示 default-autowire="no" 。如果您不希望自动装配此 bean,请尝试设置 autowire-candidate="false" http://static.springsource.org/spring/docs/2.5.x/reference/beans.html

I believe default-autowire="no" is enabled by default . i.e, if you don't specify default-autowire, it means default-autowire="no" . Try setting autowire-candidate="false" if you don't want this bean to be autowired http://static.springsource.org/spring/docs/2.5.x/reference/beans.html

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文