JSF 2.2和Spring 4和CDI在不同的层上而不会丢失Spring功能 [英] JSF 2.2 and Spring 4 and CDI on different layers without losing Spring features

查看:109
本文介绍了JSF 2.2和Spring 4和CDI在不同的层上而不会丢失Spring功能的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

阅读完所有文章后,我有些困惑。如果我在服务层中使用Weld Framework而不是简单的Spring限定符,则不需要使用其他服务。我有一项使用JavaMailSender的服务。我只是想拥有在JSF的控制器层中使用AOP的能力。

I’m a little confused after all articles that I read. I don’t want to use additional services as I’ll need if I use Weld Framework instead of simple Spring qualifier in service layer. And I have one service which uses JavaMailSender. I just want to have ability use AOP in controller layer with JSF.

在阅读有关Spring的关于JSR-229和JSR-330的支持后(甚至是Spring 3, )

I got absolutely confused after reading about support JSR-229 and JSR-330 by Spring (even Spring 3)

春季3和JSR-330 @Inject和@Named示例

这是否意味着我可以做这样的事情并不会失去使用AOP之类的Spring功能的可能性? (是的,我想。)

Does it mean that I can do smth like that and don't lose posibility use Spring features like AOP ? (Yes, I think.)

import javax.inject.Inject;
import javax.inject.Named;
import java.io.Serializable;

@Named("newClientController")
@ViewScoped
public class NewClientController implements Serializable {
@Inject
private ClientService clientService;

////......
}

@Service
@Transactional
public class ClientService {

public ClientService(){
int i = 0;
}

@Autowired
@Qualifier("clientDAOMyBatis")
private ClientDAO clientDAO;
//....
}

我研究了几天,发现几组决策

I researched several days and found several groups of decisions

1) Spring和CDI之间的桥梁

https://stackoverflow.com/questions/5510144/ cdi-bean-accessing-spring-beans
使用CDI @Inject

Prons注入Spring bean:

Prons:


  1. 简单的决定

  2. 不要失去Spring功能

缺点:


  1. 他们的声誉令人怀疑。 (错误!!!)

2)使用Spring @Component并为JSF
创建自定义ViewScope $ a $ = a href = http://blog.primefaces.org/?p=702 rel = nofollow noreferrer>> http://blog.primefaces.org/?p=702

2) Use Spring @Component and create custom ViewScope for JSF http://blog.primefaces.org/?p=702

职业:


  1. 简单的决定

  2. 不要失去Spring功能

缺点:


  1. 缺少对以下项目的支持

3)可序列化的Spring Bean(有些奇怪)

3) Serializable Spring Bean (smth strange)

https:// codereview。 stackexchange.com/questions/23790/spring-autowiring-in-managed-beans-with-support-serialization-s-this-safe

请不要关闭这个问题。我知道存在许多相关问题。
您能建议我解决这个问题的方法吗?

Please, don't close this questions. I know that many related questions exist. Could you advice me some solution for that problem?

P.S。我使用不支持JPA和基于Spring Java的配置的MyBatis,因为我想将此应用程序部署在云中。

P.S. I use MyBatis which doesn't support JPA and Spring Java-based Configuration because I want to deploy this app in cloud.

推荐答案

我想,如果您想在JSF托管Bean上使用所有Spring功能,最好将Spring用作JSF的CDI(列表中的第二个选项)。要创建自定义ViewScope,您可以尝试

I think to use Spring as CDI for JSF is best way (second option in your list) if you want all Spring features on JSF Managed Beans. to create custom ViewScope you can try this

http://blog.harezmi.com.tr/uncategorized/spring-view-scope-for-jsf-2-users/

这是将ViewScope与Spring一起使用的更好实现。

this is better implementation to use ViewScope with Spring.

-更新-

我在github上添加了一个示例项目。您可以看到它。

I added a sample project on github. You can see it.

https://github.com/bhdrk/Tutorials/tree/master/spring4-jsf22-integration

这篇关于JSF 2.2和Spring 4和CDI在不同的层上而不会丢失Spring功能的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆