1

I check my application without

<context:spring-configured/>

and the @Autowire working properly. I don't know how the container can auto inject without

<context:spring-configured/>

Here is my application-context.xml:

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans" 
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"  
    xmlns:aop="http://www.springframework.org/schema/aop" xmlns:tx="http://www.springframework.org/schema/tx" 
    xmlns:p="http://www.springframework.org/schema/p" xmlns:mvc="http://www.springframework.org/schema/mvc" 
    xmlns:context="http://www.springframework.org/schema/context" xsi:schemaLocation="http://www.springframework.org/schema/beans 
    http://www.springframework.org/schema/beans/spring-beans-3.0.xsd http://www.springframework.org/schema/context 
    http://www.springframework.org/schema/context/spring-context-3.0.xsd http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-
    mvc-3.0.xsd http://www.springframework.org/schema/tx  http://www.springframework.org/schema/tx/spring-tx.xsd">

    <context:component-scan base-package="com.somepackage" />
    <tx:annotation-driven transaction-manager="transactionManager" />
    <mvc:annotation-driven conversion-service="conversionService" />

    <bean id="multipartResolver"  class="org.springframework.web.multipart.commons.CommonsMultipartResolver" />

    <bean id="viewResolver" class="org.springframework.web.servlet.view.UrlBasedViewResolver">
        <property name="viewClass">
            <value>org.springframework.web.servlet.view.tiles3.TilesView</value>
        </property>
    </bean>

    <bean id="tilesConfigurer" class="org.springframework.web.servlet.view.tiles3.TilesConfigurer">
        <property name="definitions">
            <list>
                <value>/WEB-INF/tiles.xml</value>
            </list>
        </property>
    </bean> 

    <bean id="conversionService" class="org.springframework.context.support.ConversionServiceFactoryBean">
       <property name="converters">
           <set>
               <bean class="com.somepackage.converter.CategoryConverter"/>
           </set>
       </property>
    </bean>    
</beans>
Tiny
  • 27,221
  • 105
  • 339
  • 599

2 Answers2

2

Autowiring is working because of

context:component-scan

Check out this javadoc

geoand
  • 60,071
  • 24
  • 172
  • 190
0

You need to add context schema into your Configuration XML to use @Autowired annotation, like below :

<?xml version="1.0" encoding="UTF-8"?>
 <beans xmlns="http://www.springframework.org/schema/beans"
   xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
   xmlns:context="http://www.springframework.org/schema/context"
   xsi:schemaLocation="http://www.springframework.org/schema/beans 
       http://www.springframework.org/schema/beans/spring-beans-2.5.xsd
       http://www.springframework.org/schema/context
       http://www.springframework.org/schema/context/spring-context-2.5.xsd">

 <context:annotation-config/>

For more check the link below :

3.11. Annotation-based configuration

Also, check the difference between context:annotation-config vs context:component-scan , You were getting @Autowiring because of the context:component-scan being used in your context schema.

Community
  • 1
  • 1
Subh
  • 414
  • 6
  • 14
  • my application can @Autowire the been without . I don't know why . –  Sep 15 '14 at 09:46
  • 1
    Since you have used , so whichever comes into the package "com.somepackage" could be @Autowired that's why. – Subh Sep 15 '14 at 09:51