有 Java 编程相关的问题?

你可以在下面搜索框中键入要查询的问题!

java JSF(2.2)ViewScope在Weblogic 12.2.1.2和JDK 8上使用Spring 4.3.7(在Mac OS和Docker Oracle Linux环境上)

我尝试配置Spring4.3.7与JSF2.2.14和PrimeFaces6.0的集成。Spring应该负责管理范围,JSF中的ManagedBean成为Spring的bean

我已经在Mac OS和Docker上使用Oracle Linux配置了Weblogic 12.2.1.2

我阅读并测试了这个解决方案(http://www.concretepage.com/spring-4/spring-4-jsf-2-integration-example-using-autowired-annotation),但没有成功。我发现这个(https://github.com/michail-nikolaev/primefaces-spring-scopes/)可以防止内存泄漏问题,但不起作用

我可以感觉到Spring独立于范围(会话或视图)工作,就像一个请求bean

我的配置和一个bean示例。当我访问导航时*。xhtml。独立如果我将作用域配置为视图或会话,则会随时调用PostConstruct上定义的方法,并且分页不起作用,因为视图的状态未持久化。我不知道是什么导致了这种行为

WebConfig-Spring:

@Configuration
@ComponentScan(basePackages = { "packageC" },basePackageClasses {PackageA.class,PackageB.class})
@lombok.extern.slf4j.Slf4j
public class WebAppConfig{

@Bean
public static CustomScopeConfigurer customScopeConfigurer() {
    log.info("create customScopeConfigurer bean");
Map<String, Object> scopes = new HashMap<>();
    scopes.put("view", new CustomViewScope());

    CustomScopeConfigurer customScopeConfigurer = new CustomScopeConfigurer();
    customScopeConfigurer.setScopes(scopes);
    return customScopeConfigurer;
}
}

Faces配置。xml:

 <?xml version="1.0" encoding="UTF-8"?>
 <faces-config xmlns="http://xmlns.jcp.org/xml/ns/javaee"
  xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee 
  http://xmlns.jcp.org/xml/ns/javaee/web-facesconfig_2_2.xsd"
  version="2.2">

<application>
    <el-resolver>org.springframework.web.jsf.el.SpringBeanFacesELResolver</el-resolver>

</application>

 <lifecycle>
    <phase-listener>packagetest.listener.PhaseListener</phase-listener>
</lifecycle>

</faces-config>

WebAppInitializer:

public class WebAppInitializer implements WebApplicationInitializer {

public void onStartup(ServletContext servletContext) throws ServletException {
    log.info("call WebAppInitializer.onStartup");
    AnnotationConfigWebApplicationContext ctx = new AnnotationConfigWebApplicationContext();
    ctx.register(ServiceConfig.class);
    ctx.setServletContext(servletContext);
    servletContext.addListener(new ContextLoaderListener(ctx));
    servletContext.addListener(new RequestContextListener());
    log.info("end call WebAppInitializer.onStartup");
}
}

JSFbean示例:

@Scope("session")
@Component("accountBean")
@lombok.extern.slf4j.Slf4j
public class AccountManagedBeanImpl extends GenericManagedBeanAb<AccountEntity, Long> implements AccountManagedBean {

private static final long serialVersionUID = 4359183101897060165L;

@Autowired
AccountService accountService;

@PostConstruct
public void init() {    
    log.info("init do bean: AccountManagedBeanImpl. Escopo = session");
    this.entity = new AccountEntity();
    if (getRequest().getParameter("codigo") != null) {
        Optional op = accountService.findByPrimaryKey(Long.parseLong(getRequest().getParameter("codigo")));
        if (op.isPresent()) {
            this.entity = (AccountEntity) op.get();
        }
    }
    this.entityFilter = new AccountEntity();
    this.listEntitySelected = new ArrayList<AccountEntity>(0);
}

共 (1) 个答案

  1. # 1 楼答案

    我把同样的应用程序放在了Wildfly 9上。x和它的工作原理。我可以得出结论,Weblogic上的CDI具有不同的行为,它没有将上下文委托给SPRING DI

    我不想使用EJB,我更喜欢使用Spring服务层与Spring数据+Spring AOP集成

    我仍在寻找解决方案,但这些信息可能对某些人有用