我有一个带有 JSF 2 结束 Spring 4.3 的网络模块。在我使用的支持豆中@Autowired
用于 JAR 服务的 DI。在 EAR 模块中有 WAR、JAR 和@Service
Spring 和带有 Spring 配置文件的 JAR。
Below a 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>
当我使用时@Autowired(required=null)
在支持 Bean 中,该值为null
(没有任何例外)。我的 JSF bean
@Component
@ManagedBean
@ViewScoped
public class PortfolioController {
@Autowired(required = true)
private PortfolioService portfolioService;
...
你能帮我吗。
PortfolioController
被认为是JSF
添加上下文bean@Component
to @ManagedBean
完全错误,你不能在两个不同的上下文中将同一个类标记为bean(JSF
and Spring
).
有两种解决方案PortfolioController
春豆因此去除@ManagedBean
and @ViewScoped
或注射PortfolioController
via JSF
注入注解@ManagedProperty
@ManagedProperty("#{portfolioService}")
private PortfolioService portfolioService;
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)