How to inject dependencies with Weblogic 12.x. x?

Asked

Viewed 1,120 times

1

What is the procedure to be able to inject dependencies using @Inject of javax.inject on the Weblogic 12.x. x server? I need to download Weld and place it on project dependencies?

I noticed that Weblogic doesn’t even recognize the annotation

I tested both with my empty Beans.xml (worked on jboss 7.1.1) and with the content below:

<beans></beans>

Within the class I intend to inject my Stateless Session Bean, I simply made the reference like this:

@Inject
private TransFacadeLocal transfacade;

And when trying to use it this always null, resulting in a Nullpointerexception when trying to reference it.

The concrete class of my Stateless Session Bean is as follows:

//imports omitidos
@Stateless(mappedName = "transFacade")
@LocalBean
public class TransFacade implements TransFacadeLocal{


   public TransFacade{}
   //outros métodos omitidos

}

The local interface I’m using to inject is as follows:

//imports omitidos
@Local
public interface TransFacadeLocal{//... metodos omitidos}

To recognize the libs as @Inject of javax.inject for example I did without referencing the Weld itself, but taking advantage of libs that already came in the distribution along with OEPE/Weblogic. Are they:

  • wljarbuilder. ... Oracle Middleware Oracle_home wlserver server lib
  • Weblogic.jar ... Oracle Middleware Oracle_home wlserver server lib
  • Weblogic.server.merged.jar ... Oracle Middleware Oracle_home wlserver modules Features

    Error 500-Internal Server Error

    org.jboss.weld.exceptions.DeploymentException: WELD-001409 Ambiguous dependencies for type [TesteLocal] with qualifiers [@Default] at injection point [[field] @Inject private br.com.programa.teste.ServletTest.testeLocal]. Possible dependencies [[Managed Bean [class br.com.programa.Teste] with Qualifiers [@Any @Default], Session bean [class br.com.programa.Teste with Qualifiers [@Any @Default]; local interfaces are [Teste, Testelocal], Managed Bean [class br.com.programa.Teste] with Qualifiers [@Any @Default]] at org.jboss.Weld.bootstrap.Validator.validateInjectionPoint(Validator.java:318) at org.jboss.Weld.bootstrap.Validator.validateInjectionPoint(Validator.java:284) at org.jboss.Weld.bootstrap.Validator.validateInjectionTarget(Validator.java:342) at org.jboss.Weld.manager.Injectiontargetvalidator.addInjectionTarget(Injectiontargetvalidator.java:29) at org.jboss.Weld.manager.Beanmanagerimpl.createInjectionTarget(Beanmanagerimpl.java:943) at org.jboss.Weld.manager.Beanmanagerimpl.fireProcessInjectionTarget(Beanmanagerimpl.java:1098) at com.oracle.Injection.provider.Weld.WeldBeanManager.newBeanInstance(Weldbeanmanager.java:135) at com.oracle.Injection.integration.utils.InjectionBeanCreator.newBeanInstance(Injectionbeancreator.java:154) Weblogic.servlet.Internal.InjectionBasedWebComponentCreator.createServletInstance(Injectionbasedwebcomponentcreator.java:66) at Weblogic.servlet.Internal.Stubsecurityhelper$Servletinitaction.newServletInstanceIfNecessary(Stubsecurityhelper.java:358) at Weblogic.servlet.Internal.Stubsecurityhelper$Servletinitaction.run(Stubsecurityhelper.java:311) at Weblogic.servlet.Internal.Stubsecurityhelper$Servletinitaction.run(Stubsecurityhelper.java:288) Weblogic.security.Acl.internal.Authenticatedsubject.doas(Authenticatedsubject.java:321) at Weblogic.security.service.SecurityManager.runas(Securitymanager.java:120) at Weblogic.servlet.Provider.WlsSubjectHandle.run(Wlssubjecthandle.java:57) at Weblogic.servlet.Internal.StubSecurityHelper.initServletInstance(Stubsecurityhelper.java:98) at Weblogic.servlet.Internal.StubSecurityHelper.createServlet(Stubsecurityhelper.java:86) Weblogic.servlet.Internal.StubLifecycleHelper.createOneInstance(Stublifecyclehelper.java:71) at Weblogic.servlet.Internal.StubLifecycleHelper.(Stublifecyclehelper.java:57) at Weblogic.servlet.Internal.StubLifecycleHelper.(Stublifecyclehelper.java:31) at Weblogic.servlet.Internal.ServletStubImpl.initStubLifecycleHelper(Servletstubimpl.java:660) at Weblogic.servlet.Internal.ServletStubImpl.prepareServlet(Servletstubimpl.java:600) at Weblogic.servlet.Internal.ServletStubImpl.getServlet(Servletstubimpl.java:408) at Weblogic.servlet.Internal.ServletStubImpl.execute(Servletstubimpl.java:300) at Weblogic.servlet.Internal.TailFilter.doFilter(Tailfilter.java:25) at Weblogic.servlet.Internal.FilterChainImpl.doFilter(Filterchainimpl.java:79) at org.jboss.Weld.servlet.Conversationpropagationfilter.doFilter(Conversationpropagationfilter.java:62) at Weblogic.servlet.Internal.FilterChainImpl.doFilter(Filterchainimpl.java:79) Weblogic.servlet.Internal.RequestEventsFilter.doFilter(Requesteventsfilter.java:27) at Weblogic.servlet.Internal.FilterChainImpl.doFilter(Filterchainimpl.java:79) at Weblogic.servlet.Internal.Webappservletcontext$Servletinvocationaction.wrapRun(Webappservletcontext.java:3436) at Weblogic.servlet.Internal.Webappservletcontext$Servletinvocationaction.run(Webappservletcontext.java:3402) Weblogic.security.Acl.internal.Authenticatedsubject.doas(Authenticatedsubject.java:321) at Weblogic.security.service.SecurityManager.runas(Securitymanager.java:120) at Weblogic.servlet.Provider.WlsSubjectHandle.run(Wlssubjecthandle.java:57) at Weblogic.servlet.Internal.WebAppServletContext.doSecuredExecute(Webappservletcontext.java:2285) at Weblogic.servlet.Internal.WebAppServletContext.securedExecute(Webappservletcontext.java:2201) at Weblogic.servlet.Internal.WebAppServletContext.execute(Webappservletcontext.java:2179) at Weblogic.servlet.Internal.ServletRequestImpl.run(Servletrequestimpl.java:1572) Weblogic.servlet.Provider.Containersupportproviderimpl$Wlsrequestexecutor.run(Containersupportproviderimpl.java:255) Weblogic.work.Executethread.execute(Executethread.java:311) Weblogic.work.Executethread.run(Executethread.java:263)

  • 1

    Patrick, welcome to [en.so]! Your problem is a little vague. Could you add more details? You have the bens.xml in your project? The injected classes have some annotations that make them Beans injectable by the CDI?

  • Another tip specific to Weblogic, it already comes with a CDI implementation, you do not need to include Weld in your project (use the App Server). Take a look at the manual part specific on Icds and in the example in EXAMPLES_HOME\wl_server\examples\src\examples\javaee6\cdi. In version 12.1.1 there were some bugs related to CDI, but it seems that came out patches and that in versions 12.1.2+ everything is already working correctly.

  • @Anthonyaccioly, I haven’t been able to find these examples so far. I even carefully reinstalled OEPE Bundle to ensure that I did a Full Installation as suggested in the documentation, and after finishing the installation the supposed directory that should contain the examples does not appear.

  • According to the documentation: the examples directory should be: EXAMPLES_HOME , i.e.: ORACLE_HOME user_projects Applications However on my ORACLE_HOME there are only the following directories: ORACLE_HOME Coherence, ORACLE_HOME on, ORACLE_HOME\install,&#xA;ORACLE_HOME\inventory,&#xA;ORACLE_HOME\oepe (eclipse),&#xA;ORACLE_HOME\OPatch,&#xA;ORACLE_HOME\oracle_common,&#xA;ORACLE_HOME\oui,&#xA;ORACLE_HOME\wlserver ...&#xA;&#xA;Testei tanto no windows qto no macosx na versão OEPE 12.1.3.

  • Can anyone add tags related to the webserver name? Weblogic, weblogic12c. I don’t have that permission yet. I believe this problem is very specific to the webserver since my injections work in Jboss.

  • Since the test with Weld was not enough for the injection to work (it started to recognize the Annotation but the injected bean remains null), any idea about which jars I would have to put in the build path to enable the injection? I put some libs I found inside the server: wljarbuilder.jar, Weblogic.jar, Weblogic.server.merged.jar in the build path and he started to recognize @Inject as well, but the test is still unsuccessful.

  • Patrick, about the examples: You need to select the complete installation option: In Installation Wizard. http://docs.oracle.com/middleware/1213/wls/INTRO/examples.htm

  • In the OEPE installer version 12.1.3 it is not possible to choose between Full or Partial installation. It is all or nothing..

  • Dude, try another version of the installer then. I’m with 12.1.2 (I can’t remember which installer I used but I think it was Generic), it came with all the examples (I can zip for you, but I don’t know if it will work in another version... Nor without the specific testing domain).

  • It worked here... I used another installer that I believe to be identical... and made some different Steps in the configuration. I will detail what I did in case anyone finds the same problem. Anyway, very grateful @Anthonyaccioly.

  • Perfect Patrick. I’m glad to have helped and for your initiative to post the answer to help other users with similar problems.

Show 6 more comments

1 answer

1

Small problem laborious, but we managed to solve here both on mac and windows. We did not find exactly what caused the problem, but following this procedure I reproduced in 4 environments until now the injection finally worked. Follows the solution:

I used a 32-bit OEPE 12.1.3 installer which is a Bundle already comes with Kepler eclipse and Weblogic 12.1.3. The installation proceeded normally, in full mode even. I created a new domain using Wizard and only enabled the last option of modules... unless JAX-WS and JMS mistake. I kept the JDK of Bundle itself (Java 1.7.x) and continued the installation normally. A detail that I did different this time was on the "Advanced Configuration" screen where a list of items with check box was made available to mark: Administration Server, Node Manager, etc... I did not check any of the options.

I created an Enterprise Application with an EJB module and a WEB only. I created a test EJB with only a local interface and a public method:

public void imprimir(){
   Syso("passou pelo EJB")
}

In the build path in the EJB module, in the Libraries tab I created a "user library" and as content I selected the lib Weblogic.server.merged.jar ... Oracle Middleware Oracle_home wlserver modules Features. This is enough for annotations @Inject to be recognized by Eclipse, that is (no downloading the Weld from the outside). But as we did in the EJB project, be careful not to forget to go through the Order and Export tab to externalize the user library we created (otherwise the web project will not see it for example).

In the web project’s build path, I created a note for the EJB project (its respective dependency).

In the meta-inf folder of the ejb project, as well as in the web-inf of the web project, I created empty files with the name Beans.xml (to enable CDI)

In the web project I created a Servlet with only one doGet() method and in it I invoked the ejb bean after injecting it and finally it was not null. That is, the injection worked. I tested both injecting the bean through the local interface, and the concrete bean itself and it worked perfectly.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.