0

我有以下内容,但我的 @Autowired 出于某种原因无法正常工作,因为它仍然设置为 null:

@Component
public class Face {
    public void smile();
}  

public class Parent {
    @Autowired
    protected Face face;
}

public abstract class AbstractParent extends Parent {
}

@Named
@Path("/parent/blueParent")
public class BlueParent extends AbstractParent {
    @POST
    @Consumes("application/json")
    @Produces("text/plain")
    public void describe() {
        // crash here because face is null when I curl to /parent/blueParent
        face.smile();
    }
}

这是我的应用程序上下文

<?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">

<context:component-scan base-package="com.company.parent"/>
</beans>

有谁知道可能是什么问题?是因为@Autowired 不适用于抽象类吗?

4

0 回答 0