Can someone please provide the example of injecting hebiernate session into ejb 2 deployed on Weblogic 10.3.6 either with WELD or OpenWebBeans ?
Is it supported at all ?
Thanks
Related
As JSF 2.3, #ManagedBean and other javax.faces.bean.* annotations are deprecated and replaced with JavaEE 6 CDI.
I successfully made a sample JSF project and deployed it to WebLogic using server implementations 'glassfish.jsf.jar' and with no implementation of JSF nor CDI in the WEB-INF/lib.
But I am afraid to be stuck with Server implementation that may be out of date in sometimes + my application behave differently during work in different application servers so I think it would be better if I have control over JSF implementation.
I spent the last 4 days for searching for a way to use a custom JSF implementation (Mojarra or MyFaces) using new CDI annotations or any other DI framework but with no luck.
I got that I must use JavaEE server implementation of JSF and CDI if I want to get rid of #ManagedAnnotations.
My question: is there a way to include my preferred implementation of JSF and CDI in my WAR that will be deployed to different application servers like WebLogic and WildFly.
Note: I found an old question from 2013 with No as an answer but I want to know is this answer still valid
Edit 02/11/2018:
I successfully install a project with embedded JSF (Mojarra) and CDI (Weld) without any problem on Tomcat Server. I think it's because Tomcat is Servlet Container so there are no conflicts.
I think my problem because of the conflict between my embedded CDI and Server implementation version of Weld. I can not find a solution to make my application is as blackbox.
I used this weblogic.xml
false
<prefer-application-packages>
<package-name>!javax.servlet.*</package-name>
</prefer-application-packages>
<prefer-application-resources>
<resource-name>!javax.servlet.*</resource-name>
</prefer-application-resources>
The other answer is sort of still valid. But there are sort of other (better) options
1 Also provide the full java-ee container as part of your app.
2 Require a minimal version of specific app servers
3 Tell customers they need at least specific versions of certain libraries
In Airpal used Guice for DI framework, in my project we are using glassfish 4.1 payara server RESTful web services, Jersey version 2.21.
issue 1: if use Guice got some runtime exceptions
Error occurred during deployment: Exception while loading the app : CDI deployment failure:WELD-001409: Ambiguous dependencies for type Validator with qualifiers #Default at injection point [UnbackedAnnotatedField] #Inject private org.hibernate.validator.internal.cdi.interceptor.ValidationInterceptor.validator at org.hibernate.validator.internal.cdi.interceptor.ValidationInterceptor.validator(ValidationInterceptor.java:0) Possible dependencies: - org.apache.bval.cdi.ValidatorBean#33aeb01, - ValidatorBean [id=org.hibernate.validator.internal.cdi.ValidatorBean_default] . Please see server.log for more details.
issue2: if didn't use Guice how can bind airlift client in jersey 2.21 RESTful.
Please help me. anybody know this issue who are using Airpal+presto+glassfish4.1+jersey2.21+maven3.0
It seems that since both Guice and standard Java EE CDI use the same #Inject annotations, the CDI mechanism is triggered but fails to find dependencies, because your applcation is configured with Guice.
The simplest solution with GlassFish/Payara is to disable implicit CDI when deploying the application (there is a checkbox in Admin console when deploying, or an option to asadmin command).
You can disable CDI in the application archive in a XML descriptor too. Have a look at Payara Server docs about disabling CDI or filtering CDI scanning. Note that most options are available only in Payara Server and not in GlassFish 4.1.
The CDI is triggered either by
- putting beans.xml into you application (I don't expect you put it there, because you're using Guice, but check if it wasn't generated by your IDE for some reason)
- annotating one or more classes with annotations that trigger CDI - e.g. any EJB annotation (#Stateless, #Stateful,...)
I've found some tutorials about integrating JSF technology with Spring Boot, but it seems a rather involved work to get OmniFaces working with Spring Boot. Is it a good idea to integrate these two together at all?
First of all, Java EE and Spring are competing frameworks. Generally it's the easiest to pick the one or the other instead of attempting to mix them. It will in long term end up in less confusion to beginners and less annoyances as to interoperability.
The Java EE framework is geared towards Java EE containers (WildFly, TomEE, Payara, etc), while the Spring framework is geared towards barebones servlet containers (Tomcat, Jetty, etc). JSF, whilst being part of Java EE framework, initially didn't require much of other Java EE artifacts as dependency so that it could effortlessly run in barebones servlet containers as well. Only JSTL was required as another part of Java EE, which is rather trivial to manually install in a barebones servlet container.
Since JSF version 2.0, an optional Bean Validation (JSR303) dependency was added, which is also easy to install in a barebones servlet container.
Since JSF version 2.2, an optional CDI dependency was added, which is in case of Weld also easy to install in a barebones servlet container. However, here comes the trouble: Spring only partially supports CDI. Anything from javax.inject.* is supported, but nothing from javax.enterprise.context.* is supported. This forces users less or more to use Spring-managed beans instead of CDI-managed beans.
As per the future JSF version 2.3, JSF own #ManagedBean facility will be deprecated, CDI dependency will be made required, and more optional Java EE dependencies will be added: WebSocket (JSR356) and JSONP (JSR353). CDI being fully required doesn't play well together with Spring as they refuse to fully implement CDI.
OmniFaces in turn, is fully geared to JSF. OmniFaces 1.x is targeted to JSF 2.0 and doesn't require CDI. OmniFaces 1.1x is even CDI-less. OmniFaces 2.x is targeted to JSF 2.2, with the difference that CDI is made required instead of optional. This is done so because OmniFaces is designed with "best practices" in mind and tries to force users to move to CDI for bean management, particularly because JSF will by itself also head in the direction of making CDI required and thus OmniFaces 2.x users will be better prepared for the future.
Given the CDI issues explained above, you should by now probably realize that you'd best pick CDI-less OmniFaces 1.1x in case you want to use Spring instead of Java EE. The latest 1.1x version is 1.14 and this happens to be integrated as part of JoinFaces.
What is JoinFaces?
This project enables JSF usage inside JAR packaged Spring Boot Application.
It autoconfigures PrimeFaces, PrimeFaces Extensions, BootsFaces, ButterFaces, RichFaces, OmniFaces, AngularFaces, Mojarra and MyFaces libraries to run at embedded Tomcat, Jetty or Undertow servlet containers.
Although I'm no Spring guy and can't tell from own experience, I'd say that JoinFaces is your best pick in case you'd like to go ahead with Spring Boot + JSF.
Note that whilst JoinFaces site says it supports CDI annotations, it does not mean that it supports the CDI implementation, it really only supports the annotations from javax.inject.* package.
See also:
What exactly is Java EE?
Backing beans (#ManagedBean) or CDI Beans (#Named)?
How to install and use CDI on Tomcat?
When is it necessary or convenient to use Spring or EJB3 or all of them together?
Spring JSF integration: how to inject a Spring component/service in JSF managed bean?
So, I have a tomcat 8 + jersey 2.5.1 + weld CDI app that works very well in most cases. Where it fails is that I am unable to intercept jersey resource method calls with a CDI interceptor. This makes sense because a jersey resource class is not a CDI bean. Then, is there any way to make a CDI interceptor work in jersey? Another way to ask this question: Can a CDI bean be used as a Jersey resource?
Thanks!
EDIT:
Before I wrote my RESTful resources using Jersey, I had CDI interceptors that were used to begin and commit database transactions. I really need to follow the same or similar pattern to implement this cross-cutting transaction injection in my RESTful jersey resources. That is the main reason for asking this question.
Thanks again!
Can a CDI bean be used as a Jersey resource?
Yes, but since Jersey's DI is based on hk2 and not CDI, you need a bridge.
In glassfish such a bridge is realized by the module jersey-gf-cdi:
<dependency>
<groupId>org.glassfish.jersey.containers.glassfish</groupId>
<artifactId>jersey-gf-cdi</artifactId>
<version>2.6</version>
</dependency>
The module registers itself automatically and works on Tomcat beautifully (assuming you have correctly bootstrapped both Jersey and Weld).
Unfortunately, the versions before 2.6 relies on JNDI only, searching the provider under 'java:comp/BeanManager' which Tomcat does not allow.
A fix for this behaviour is available for 2.6 (a pull request I made some time ago), and falls back on CDI.current().getBeanManager().
I tested it on Tomcat 7 and works correctly, should work on Tomcat 8 too.
Adam Bien in one presentation recommends that you separate your Service (CDI or EJB) class from your RESTful resources class. His reason was that the RESTful class usually uses the HttpHeaders injected by Jersey yet not available in the CDI or EJB containers. The hazard is that your RESTful classes could be injected a Null reference of HttpHeaders if any CDI client like the JSF framework uses it.
Thanks to your self-answered question. You have just showed a second use case that validates Adam Bien's recommendation.
Simply keep them apart!
My simple JSF app is running on JBoss 7 but when I deploy it to Jetty - JSF annotations are ignored, and I have to define ManagedBean in faces-config.xml to make it work because managedBean resolved to null when I submit the form. JBoss is not mentioned in pom.xml dependencies, so looks like JSF by default tied up with JBoss.
How to make project stop being close friends with JBoss?
JSF 2.0 is part of the Java EE specification so it is definitely not bound to an application server in particular.
You should check out that the version of the Web container (Jetty) supports JSF 2.0 and that you have added all the required dependencies.
Hope it helps
Francesco