我有一個JSF 2結束Spring 4.3的webmodule。在支持bean中,我使用@Autowired
作爲JAR服務的DI。在EAR模塊中有WAR,JAR和@Service
Spring和JAR以及Spring配置文件。Spring @Autowired(required = true)爲null
下面一個web.xml
片段:
<context-param>
<param-name>locatorFactorySelector</param-name>
<param-value>classpath:beanRefContext.xml</param-value>
</context-param>
<context-param>
<param-name>parentContextKey</param-name>
<param-value>sharedContext</param-value>
</context-param>
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>classpath:applicationContext.xml</param-value>
</context-param>
<listener>
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>
<listener>
<listener-class>org.springframework.web.context.request.RequestContextListener</listener-class>
</listener>
applicationContext.xml
:
<context:annotation-config />
<context:spring-configured />
<!-- package of @Service class in jar module in EAR-- >
<context:component-scan base-package="com.ipdb.service" />
beanRefContext.xml:
<bean id="sharedContext" class="org.springframework.context.support.ClassPathXmlApplicationContext"> <constructor-arg> <list> <value>spring-ctx.xml</value> </list> </constructor-arg> </bean>
當我在後臺bean使用@Autowired(required=null)
值null
(有沒有任何例外)。我的JSF豆
@Component
@ManagedBean
@ViewScoped
public class PortfolioController {
@Autowired(required = true)
private PortfolioService portfolioService;
...
請問你能幫助我嗎?
這不是一個Spring bean和Spring不負責管理或自動裝配它注入
PortfolioController
。 – chrylis由於你的問題最初是用[spring-mvc]標記的,下面是一些需要思考的食物:http://stackoverflow.com/q/18744910 – BalusC