Spring Autowired Exception when a remote ejb is down - java

Hi,
I have a simple question that I am not able to solve.
I'm using Spring 3 to lookup Remote ejbs and I added lazy-init=true into bean definition because my application must starting
also if some ejb is down.
Unfortunately my controller when autowiring of an ejb that is down, I get "Injection of autowired dependencies failed".
Someone can help me! Is #Autowired not lazy? It's possible, using spring, start my web application also if some remote ejb is not started?

Related

Spring: How to load my bean as the first bean when server startsup

I have a java application based upon spring and I have a bean that runs some connection test logic during server startup. If the connection test fails, I stop the server.
I need this bean as the first one to be loaded before any other beans performs some operations using the connection string.
Can someone help me figure out how I can load this connection test bean as the first bean please.
Ways tried:
Bean lifecycle hooks such as InitializingBean, init-method, #PostConstruct won't work as they will get invoked for my specific bean but can't control what beans gets loaded before my desired bean.
Update:
depends-on or #DependsOn worked.
Thanks

How to bind a spring bean to JNDI so that it can be accessed from a different war?

I have a WAR and an EAR deployed in wildfly. The ear has a spring boot application which spins up a particular bean. I want that instance of the bean to available in jndi something like
java:/mySpringBean
so that I can do a lookup from the WAR (which again has a spring context).
The goal is to reuse the instance which was instantiated from the EAR spring boot.
First of all, I'm not sure if that's even possible,
I tried
https://konstantinpavlov.net/blog/2009/01/01/how-to-export-spring-managed-bean-to-jndi/
but it doesnt seem to be working, after I added the code from above I do not see a an entry in wildfly management console under the JNDI view.
Pick one of the classes where your spring application is bootStrapping. In my case there was a starupClass which would run upon application start. Then I #Autowired the bean to that class. Got the IntialContext and bind the bean.
Context ctx = new InitialContext();
ctx.bind("mySpringBean", mySpringBean);

How can I view the Bean Graph for #Autowired beans in Spring STS?

I am able to view the Bean Graph for any beans wired through XML, but when I have beans that are #Autowired through annotations, it doesn't show any arrows between them.
According to STS #171 and STS #1066 it was implemented a long time ago.
Note: Last tested with STS 3.4.0.RELEASE
If I deploy to tcServer and do Live Bean Graph, then it works, but not using regular view.
The improvement feature was requested and even closed; but new tickets still say that feature is requested - and not closed yet even (STS-2396) in 2.8. I haven't succeeded getting there. No joy :(
Issue says - "When STS is resolving autowired beans for either validation purposes or for the bean graph, it seems to only to be able to find beans that have their type explicitly defined."
If you are using Spring boot you can use spring acutator to view all the beans..
Spring acutator enables /beans endpoint which shows all beans in JSON format.
Once you start the Spring boot app all you need to do is http://localhost:8080/beans

Integrating EJB3 with Spring

I'm building application with EJB and Spring 3. I have three maven modules - Spring jars, EJB jar and web part. In the web part I want to call my EJB session bean. Here comes the code of it:
#Controller
public class IndexController {
#EJB
PaymentRemote paymentRemote;
}
I have also an application context file, with the content:
<jee:local-slsb id="paymentRemote" jndi-name="ejb/myBean"
business-interface="net.learntechnology.ejb.PaymentRemote"/>
and
<bean class="org.springframework.context.annotation.CommonAnnotationBeanPostProcessor">
<property name="alwaysUseJndiLookup" value="true"/>
In my ejb module I have an interface:
#Local
public interface PaymentRemote {
}
Unfortunately when I deploy it on JBoss as 5 i get the following error:
Error creating bean with name 'paymentRemote': Invocation of init method failed; nested exception is javax.naming.NameNotFoundException: ejb not bound.
I saw a lot of examples in net and all are configured like this. I'm stuck with it...
Could any one help me with this? I would be more than grateful!
For JBOSS the proper pattern is:
application-name/bean/remote or local
Since my comment turned out to be the answer, I'll rephrase it....
Make sure that the EJB is actually bound to JNDI under the name you're expecting. The error message suggests that it's not.
In JBoss, to the JMX Console, look for the JNDIView object, and invoke its list method. If your EJB is present on ejb/myBean, it should appear here. If not, look for its under a different name, and bind to that.

Weblogic 10.3.1 gives 'Dependency injection failure' warning when publishing code

Weblogic 10.3.1 gives me a "Dependency injection failure" when I publish my code; the publish itself succeeds. I am working via Eclipse.
Basically I publish an ear with a web service aaa.MyWebServicePort that has a bean bbb.MyBean declared as local variable with the ejb 3.0 #EJB annotation. bbb.MyBean is also in the ear as well as a client project with the interfaces defined.
After publishing the web service works on the appserver and calls bbb.MyBean. So why the warning?
Details of the warning in the console window of Eclipse: Error creating bean with name 'aaa.MyWebServicePort': Initialization of bean failed; nested exception is [...] BeanCreationException: Dependency injection failure: can't find the bean definition about class interface bbb.MyBean; nested exception is [...] NoSuchBeanDefinitionException: No unique bean of type bbb.MyBean is defined: No beans of type bbb.MyBean;
There may be a couple of issues at work here. I'm getting a very similar error in just a straight servlet that is trying to load an ejb that isn't packaged in the same ear, I'm still trying to track that down. I also know that there is a difficulty when loading EJB v2.x that is supposed to be fixed in Weblogic 10.3.3.
If you find anything please let me know, and I'll do the same. One thing I have noticed is that if I load the EJB via initialContext.lookup, it works fine.
YMMV

Categories