Announcement Announcement Module
Collapse
No announcement yet.
autowired issue Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • autowired issue

    hi

    i'm beginning with spring 3.0

    i try to use annotation to reduce xml file

    i get:

    Code:
    org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'supervisionController': Injection of autowired dependencies failed; 
    
    nested exception is org.springframework.beans.factory.BeanCreationException: Could not autowire field: private com.h23v.service.IUserService com.h23v.controller.UserController.userService; 
    
    nested exception is org.springframework.beans.factory.NoSuchBeanDefinitionException: No matching bean of type [com.h23v.service.IUserService] found for dependency: expected at least 1 bean which qualifies as autowire candidate for this dependency. Dependency annotations: {@org.springframework.beans.factory.annotation.Autowired(required=true)}
    my controler class
    Code:
    @Controller
    public class UserController {
        
        @Autowired    
        private IUserService userService; 
    	...
    }

    my service class
    Code:
    @Service
    public class UserService implements IUserService {
    
        @Autowired
        private IUserDao userDao;
        ...
    }

    my dao class
    Code:
    @Repository
    public class UserDaoImpl extends JdbcDaoSupport  implements IUserDao{
        @Override
        public List<User> getAllUser() {
    	...
    	}
        ...
    }
    a part of my dispatch servlet file
    Code:
    <context:component-scan base-package="com.h23v.controller"/>
    <context:annotation-config/>
    a part of my application context file
    Code:
    	<bean id="propertyConfigurer"
              class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer"
              p:location="/WEB-INF/jdbc.properties" />
        
        <bean id="dataSource"
              class="org.springframework.jdbc.datasource.DriverManagerDataSource"
              p:driverClassName="${jdbc.driverClassName}"
              p:url="${jdbc.url}"
              p:username="${jdbc.username}"
              p:password="${jdbc.password}" />
    i don't understand the error

    any idea

    thanks

  • #2
    apart from

    <context:annotation-config />


    you also need to add this


    Code:
    <context:component-scan base-package="your.package.name.*" />
    <context:component-scan base-package="your.other.package.here*" />

    Comment


    • #3
      Sorry, i just noticed that you already have that.

      Comment


      • #4
        The package you provided in your component-scan doesn't match withe package that your bean is in.

        Comment


        • #5
          ok i changed for

          Code:
          <context:component-scan base-package="com.h23v.*"/>
          <context:annotation-config/>
          now i get this error
          Code:
           nested exception is java.lang.IllegalArgumentException: 'dataSource' or 'jdbcTemplate' is required
          spring is not supposed to manage automatically dataSource, jdbcTemplate when autowired is used?

          i tried to add in application-context without success

          Code:
          <bean id="jdbcTemplate" class="org.springframework.jdbc.core.JdbcTemplate">   
                  <property name="dataSource" ref="dataSource" />   
          </bean>
          any idea?

          Comment

          Working...
          X