spring autowiring not working

后端 未结 2 900
挽巷
挽巷 2021-02-07 21:46

Hi, I am using spring 3.0 with Quartz in a scheduler class. I have created the application context by

private static final ClassPathXmlApplicationContext appli         


        
相关标签:
2条回答
  • 2021-02-07 22:17

    Atlast i got it resolved by adding the

    <context:component-scan base-package="your.package"/> 
    

    in my applicationContext.xml. Thank u all for your support.

    0 讨论(0)
  • 2021-02-07 22:26

    You haven't provided the UserService class source code so I can't be sure about your problem. Looks like the UserService class is missing a 'stereotype' annotation like @Component or @Service. You also have to configure the Spring classpath scanning using the following configuration:

        <?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-3.0.xsd
               http://www.springframework.org/schema/context
               http://www.springframework.org/schema/context/spring-context-3.0.xsd">
    
         <!-- Add your classes base package here -->          
         <context:component-scan base-package="your.package"/>
    
       </beans>
    

    Your beans must include one of the Spring stereotype annotations like:

    package your.package;
    
    @Service
    public class UserService{
    }
    
    0 讨论(0)
提交回复
热议问题