Glassfish replaces managed bean with fully qualified name with just class name - java

I'm currently adding functionality to a web platform written in Java and using GlassFish 3.1 as the server. This is a highly complex platform in terms of maintenance and my efforts with googling and reading through documentation were fruitless.
When deploying I get the following warning:
WARNING: JSF1074: Managed bean named 'SomeClass' has already been registered.
Replacing existing managed bean class type com.example.package.SomeClass with SomeClass.
That leads to the exception below when the web page is opened. My guess is this happens because the managed bean was registered without the package name.
java.lang.NoClassDefFoundError: Could not initialize class SomeClass
The bean is annotated the following way
#ManagedBean(name="SomeClass")
#SessionScoped
public class SomeClass { ... }
If I undeploy, restart Glassfish and deploy again, sometimes the fully qualified managed bean is registered and the problem (temporarily) solved. This just adds to my confusion.
So, my question is: what could be causing GlassFish to replace a managed bean with the fully qualified name with another using just the class name?

Related

Is there an alternative to mimic the import annotation for solving identical bean issue?

While working in development in a Spring Boot application there is an AppContext defined which is importing various other application contexts from a library.
The issue is that two of these application contexts have a bean defined with the same name and hence when the parent application is started by the Spring container and it tries to load the various contexts from the library being imported by the AppContext it throws an exception saying there is already a bean defined with this name when it comes to the second context that contains the identical bean.
Lets say I cannot make any code changes to the application contexts from the library since they are auto-generated files and hence the bean names and their method names are being auto generated.
As we know the Spring container is going to create a bean with the method name and the method name for the bean is the same in both application contexts.
How can I resolve this problem.??
Mimicking the import annotation is just a thought I came up where I do not import the second context and try with Spring annotations to qualify the second context with a separate name...

First Spring4 MVC Attempt not loading with Tomcat 7

Im fairly new to spring mvc and Im trying to launch a extremely simple project that will just display a greeting on a blank page but for some reason I cannot seem to get it to run on the tomcat server, I have gone over every little piece of code and I do not believe there are any mistakes as well as made sure that the tomcat server is configured correctly, any help anyone can give me would be appreciated (This isn't any kind of assignment for anything , this is purely for me trying to learn Spring MVC and learning the proper configuration, because after researching for hours I cannot find anything wrong with it)
I also did this purely in java, no xml. Did not use any dependency managers either ( No Maven or Gradle ) but I do have all necessary jars
I first start by configuring the dispatcher servlet and pass it the webConfig so that the application context can load beans via component scan, since this is a simple project I have no RootConfig class
In my WebConfig I enable Spring MVC ,I give ComponentScan the base package that will search for all Controller classes to create beans for the application context and I create a simple view resolver that will wrap view names with the specified prefix and suffix
My Controller again is really simple I annotate the class as the default handler for "/" requests and map the sayHello method to handle requests for "/home" where I attach a simple message to the model(map) and return the view name
And finally my view which displays the message, The tags in the header of the jsp I know are useless since I'm not using any tags in the form they are just something left over from a previous attempt
When I run this application on the tomcat server I get the following, Im running Tomcat 7 which does support spring mvc java configuration
The tomcat server is running properly
Project is in the webapps directory of tomcat server
And to the best of my knowledge the server configurations are correct
Console output
- Solution -
As mentioned below in the comments the warning I got was
SpringProjLibs is a user library I created and placed all my spring jars inside
This comment along with some research on this warning led me to realize I had failed to add the library to the deployment assembly like below (the entry highlighted in blue was not there , I added that) after adding the line in blue it solved that problem
IMPORTANT
Im adding a follow up to this post since this still pertains to my original question. After completing the above step it resolved THAT issue but another issue presented itself.
I got the following error and tomcat failed to launch
Jun 18, 2018 5:57:37 PM
org.springframework.web.servlet.DispatcherServlet initServletBean
SEVERE: Context initialization failed
org.springframework.beans.factory.BeanCreationException: Error
creating bean with name 'requestMappingHandlerAdapter' defined in
class
org.springframework.web.servlet.config.annotation.DelegatingWebMvcConfiguration:
Instantiation of bean failed; nested exception is
org.springframework.beans.factory.BeanDefinitionStoreException:
Factory method [public
org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter
org.springframework.web.servlet.config.annotation.WebMvcConfigurationSupport.requestMappingHandlerAdapter()]
threw exception; nested exception is
org.springframework.beans.factory.BeanCreationException: Error
creating bean with name 'mvcValidator' defined in class
org.springframework.web.servlet.config.annotation.DelegatingWebMvcConfiguration:
Invocation of init method failed; nested exception is
java.lang.NoClassDefFoundError: com/fasterxml/classmate/Filter
After doing some research I discovered that contrary to what ive studied and seen in online material the annotations #EnableWebMvc and #ComponentScan together in the WebConfig class were causing this issue. I resolved this issue by moving the #EnableWebMvc annotation to the Initializer class , now my classes look like the following
This resolved all my issues and my project launched successfully

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.

Java EJB interface

I have been working through this tutorial. Halfway though it creates an interface and facades for an EJB. Can anyone tell me when I reference the interface using the #EJB annotation, where does it actually make the link between the interface and the actual enterprise java bean itself.
Thanks for the help.
~ Kyle.
It is AFAIK not mandated by the J2EE specification how this is actually solved or implemented by the application server. The most common solution is that the app server uses its own mapping between bean class names and JNDI names, so that depending on the bean class name, it is bound to a specific JNDI path when deploying the application and the same class name -> JNDI path conversion is used for injecting the EJB reference on the "client side".
It will be done inside the EJB container.
When you add this annotation, you'll actually be telling the IoC container of your application server which implementation of the given EJB you want.

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