Disable spring autowire

I have an application with struts2.2 and spring 3.1 and I want to disable autwire spring. I searched googled a bit and found that I need to put in the <beans> default-autowire="no" , but this does not work.

Then I fount that I can declare it for each <bean> as follows: <bean autowire="no"> , but this also does not work.

When I turned on spring debug logger, I can see many messages like:

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

and the corresponding entry in 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> 

Why is spring trying to auto-install this action while I manually defined the dependency here, and I defined auto-wire="no" ?

Or this message tells me that the wiring was done by type through the constructor (as I wanted), and "Autowiring by type" means that out of 4 parameters, he matched the intermediate service with my variable, the intermediate service by type (and not in order or what something else)?

+4
source share
3 answers

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

It has been raised before; I do not remember any real permission. I returned it again to find out if it can be resolved in the next release, where we are doing some significant cleanup.

Change There is also a constant struts.objectFactory.spring.autoWire.alwaysRespect , which is false by default; try setting it to true . I don’t remember what is the point of Boolean means, which, or, if it has an effect, are now looking at it.

+5
source

The way around it (until it is fixed) is to simply name your field / constructor arguments and your beans differently, so spring cannot match them.

+1
source

I believe that default-autowire = "no" is enabled by default. those. if you do not specify default-autowire, this means default-autowire = "no". Try setting autowire-candid = "false" if you do not want this bean to be auto-notified http://static.springsource.org/spring/docs/2.5.x/reference/beans.html

0
source

Source: https://habr.com/ru/post/1385228/


All Articles