Injection of autowired dependencies failed; nested exception is org.springframework.beans.factory.BeanCreationException:

前端 未结 2 999
轻奢々
轻奢々 2020-12-28 16:55

I am creating web application using Spring, Hibernate, Struts, and Maven.

I get the below error when I run mvn clean install command:

o         


        
相关标签:
2条回答
  • 2020-12-28 17:30

    Use component scanning as given below, if com.project.action.PasswordHintAction is annotated with stereotype annotations

    <context:component-scan base-package="com.project.action"/>
    

    EDIT

    I see your problem, in PasswordHintActionTest you are autowiring PasswordHintAction. But you did not create bean configuration for PasswordHintAction to autowire. Add one of stereotype annotation(@Component, @Service, @Controller) to PasswordHintAction like

    @Component
    public class PasswordHintAction extends BaseAction {
        private static final long serialVersionUID = -4037514607101222025L;
        private String username;
    

    or create xml configuration in applicationcontext.xml like

    <bean id="passwordHintAction" class="com.project.action.PasswordHintAction" />
    
    0 讨论(0)
  • 2020-12-28 17:31

    You need to provide a candidate for autowire. That means that an instance of PasswordHint must be known to spring in a way that it can guess that it must reference it.

    Please provide the class head of PasswordHint and/or the spring bean definition of that class for further assistance.

    Try changing the name of

    PasswordHintAction action;
    

    to

    PasswordHintAction passwordHintAction;
    

    so that it matches the bean definition.

    0 讨论(0)
提交回复
热议问题