문제

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.

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

Spring 3 And JSR-330 @Inject And @Named Example

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) Bridge between Spring and CDI

https://stackoverflow.com/questions/5510144/cdi-bean-accessing-spring-beans Injecting a Spring bean using CDI @Inject

Prons:

  1. Simple decision
  2. Don't lose Spring features

Cons:

  1. They have doubtful reputation. (bugs !!!)

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

Prons:

  1. Simple decision
  2. Don't lose Spring features

Cons:

  1. Absent implementation of support for destruction callbacks.

3) Serializable Spring Bean (smth strange)

https://codereview.stackexchange.com/questions/23790/spring-autowiring-in-managed-beans-with-support-for-serialization-is-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. I use MyBatis which doesn't support JPA and Spring Java-based Configuration because I want to deploy this app in cloud.

도움이 되었습니까?

해결책

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/

this is better implementation to use ViewScope with Spring.

-- UPDATE --

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

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

다른 팁

One of my blog's readers reports that Spring beans are serializable in the latest version of Spring 3.2 (and hopefully Spring 4, but he didn't say anything about it). So you can use a standard JSF 2.2 @ViewScoped controller and have your Spring beans injected as managed properties. That's a tad unusual, because that's a third annotation (@ManagedProperty instead of @Autowire or @Inject). But I'm reported it works fine.

Read the full story (it's a bit too long to copy it here) at my blog.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top