我有以下内容,但我的@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不能用于抽象类吗?