What is the best way to mix Spring MVC and CDI / JEE6?

I am not a fan of JSF. Spring MVC makes a lot of sense to me, and I used it in the past.

Can you tell me about this or give advice on its integration in JEE6, as well as share and receive from CDI.

I don't mind having an application context for MVC stuff only, but if I use @Inject or @EJB in my MVC controllers, what will happen wrong?

Seam3 seems interesting though it's ready for production?

+3
source share
3 answers

Can you tell me about this or give advice on its integration in JEE6 and share and receive with CDI

, , , - CDI DI Spring, . , CDI Spring MVC, CDI beans. JavaOne 2010: Java EE 6 " ?" :

SpringMVC CDI? = > : CDI beans ( , SpringMVC ).

Java EE 6 (CDI/EJB 3.1) XOR Spring Core Reloaded.

MVC, @Inject @EJB MVC-, ?

Spring " " JSR-330, @EJB. , , Spring . , CDI (JSR-299).

+1

- JAX-RS ( JSP) JSP . , Spring Java EE.

, HomeController:

@Path("/")
@Stateless
public class HomeController {

    @Context
    HttpRequest request; // Injects request object so you set attributes.

    @EJB // Inject your EJB
    EmployeeServiceLocal employeeService;

    @GET
    public Viewable getHomePage() {

        Employee employee = employeeService.getEmployee();
        request.setAttribute("employee", employee);
        return new Viewable("/home.jsp", null);
    }
}

JSP home.jsp, JSP . , JAX-RS - RESTful, , , , REST.

+3

CDI Spring , CDI-to-w761 BeanFactoryPostProcessor, beans CDI BeanManager Spring.

, , Spring DI CDI, .

WAR -, WEB-INF/lib. CDI-to- Spring WEB-INF/lib CDI bean, - bean Spring DI.

CDI BeanManager JNDI Spring factory bean CDI bean.

: - MVC Spring Java EE 6.

+1
source

Source: https://habr.com/ru/post/1771387/


All Articles