Stateless Bean is null - java

It was working earlier when I was jersey 1.1. But now it says this.userBean is null.
Apart from that there is one warning in the log related com.sun.faces.flow.FlowDiscoveryCDIHelper is deprecated from CDI 1.1!
logs:
08:30:45,161 INFO [org.jboss.as.server.deployment] (MSC service thread 1-4) WFLYSRV0027: Starting deployment of "ejb2.war" (runtime-name: "ejb2.war")
08:30:45,753 INFO [org.jboss.weld.deployer] (MSC service thread 1-3) WFLYWELD0003: Processing weld deployment ejb2.war
08:30:45,783 INFO [org.jboss.as.ejb3.deployment] (MSC service thread 1-3) WFLYEJB0473: JNDI bindings for session bean named 'UserSessionBean' in deployment unit 'deployment "ejb2.war"' are as follows:
java:global/ejb2/UserSessionBean!com.enovate.assignment.ejb2.UserSessionBeanLocal
java:app/ejb2/UserSessionBean!com.enovate.assignment.ejb2.UserSessionBeanLocal
java:module/UserSessionBean!com.enovate.assignment.ejb2.UserSessionBeanLocal
java:global/ejb2/UserSessionBean
java:app/ejb2/UserSessionBean
java:module/UserSessionBean
08:30:45,845 INFO [io.jaegertracing.internal.JaegerTracer] (MSC service thread 1-3) No shutdown hook registered: Please call close() manually on application shutdown.
08:30:45,999 INFO [io.smallrye.metrics] (MSC service thread 1-3) MicroProfile: Metrics activated (SmallRye Metrics version: 2.4.2)
08:30:46,008 WARN [org.jboss.weld.Bootstrap] (MSC service thread 1-3) WELD-000146: BeforeBeanDiscovery.addAnnotatedType(AnnotatedType<?>) used for class com.sun.faces.flow.FlowDiscoveryCDIHelper is deprecated from CDI 1.1!
08:30:46,210 INFO [javax.enterprise.resource.webcontainer.jsf.config] (ServerService Thread Pool -- 126) Initializing Mojarra 2.3.14.SP01 for context '/ejb2'
08:30:47,353 INFO [org.wildfly.extension.undertow] (ServerService Thread Pool -- 126) WFLYUT0021: Registered web context: '/ejb2' for server 'default-server'
08:30:47,440 INFO [org.jboss.as.server] (DeploymentScanner-threads - 2) WFLYSRV0016: Replaced deployment "ejb2.war" with deployment "ejb2.war"
08:30:47,448 INFO [org.jboss.as.repository] (DeploymentScanner-threads - 2) WFLYDR0002: Content removed from location C:\Users\teoti\Desktop\office\wildfly-21.0.2.Final\standalone\data\content\15\e071e0f42a2e0339da8b4d636a6496c5b1146e\content
08:33:05,177 ERROR [io.undertow.request] (default task-1) UT005023: Exception handling request to /ejb2/webapi/register: javax.servlet.ServletException: java.lang.NullPointerException: Cannot invoke "com.enovate.assignment.ejb2.UserSessionBeanLocal.isUserPresent(String)" because "this.userBean" is null
web.xml:
<?xml version="1.0" encoding="UTF-8"?>
<!-- This web.xml file is not required when using Servlet 3.0 container,
see implementation details http://jersey.java.net/nonav/documentation/latest/jax-rs.html -->
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://xmlns.jcp.org/xml/ns/javaee" xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/web-app_4_0.xsd" id="WebApp_ID" version="4.0">
<servlet>
<servlet-name>Jersey Web Application</servlet-name>
<servlet-class>org.glassfish.jersey.servlet.ServletContainer</servlet-class>
<init-param>
<param-name>jersey.config.server.provider.packages</param-name>
<param-value>com.enovate.assignment.ejb2</param-value>
</init-param>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>Jersey Web Application</servlet-name>
<url-pattern>/webapi/*</url-pattern>
</servlet-mapping>
</web-app>
services:
import javax.ejb.EJB;
import javax.ws.rs.FormParam;
import javax.ws.rs.POST;
import javax.ws.rs.Path;
import javax.ws.rs.Produces;
import javax.ws.rs.core.MediaType;
import javax.ws.rs.core.Response;
#Path("")
public class Service
{
#EJB
UserSessionBeanLocal userBean;
#POST
#Produces(MediaType.APPLICATION_JSON)
#Path("register")
public Response register(#FormParam("userName") final String name, #FormParam("userPassword") final String pass, #FormParam("userEmail") String email)
{
if (userBean.isUserPresent(email))
return Response.ok("Email already registered!!").build();
userBean.addUser(new User(name, email, pass));
return Response.ok("Registered!!").build();
}
}
UserSessionBean:
import java.util.ArrayList;
import javax.ejb.Stateless;
#Stateless
public class UserSessionBean implements UserSessionBeanLocal
{
static ArrayList<User> usersList = new ArrayList<User>();
static int userCount = 0;
User u = null;
public boolean isUserPresent(final String email)
{
return usersList.stream().anyMatch(d -> d.getEmail().equals(email));
}
public void addUser(User newUser)
{
usersList.add(newUser);
userCount++;
}
}
User:
public class User
{
private String name;
private String password;
private String email;
User(final String name, final String email, final String password)
{
this.name = name;
this.email = email;
this.password = password;
}
...
}
I thought it would work fine but I don't know how it is null. Maybe is related to CDI warning of log or something related to newer version of jersey or #EJB not working. I also tried adding beans.xml file.
Any help is appreciated

The reason was something related to Non-managed bean. And I can not use #EJB to initialize the bean, I have to use Jndi lookup way like this inside function:
#POST
#Produces(MediaType.APPLICATION_JSON)
#Path("register")
public Response register(#FormParam("userName") final String name, #FormParam("userPassword") final String pass, #FormParam("userEmail") String email)
{
UserSessionBeanLocal userBean = null;
try
{
InitialContext ic = new InitialContext();
userBean = (UserSessionBeanLocal)ic.lookup("java:global/ejb/UserSessionBean!com.demo.ejb.UserSessionBeanLocal");
} catch (NamingException e)
{
e.printStackTrace();
}
...

If you only want to use #EJB this might work:
I was using jersey in the project and I feels like there is some problem with jersey libraries.
So I deleted all the dependency inside the dependecies below build from the pom.xml and update the project
Added to javaee-api-8.0.jar file to the classpath
Clear the everything inside the web-app (everything)
Added root resource file by extending javax.ws.rs.core.Application like here and it worked

Related

Spring websocket in embedded tomcat 8.0.21

I want to create a WebSocket based on an example. The only spin is that I'm running my application in embedded tomcat.
package com.test.websocket;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.web.socket.CloseStatus;
import org.springframework.web.socket.TextMessage;
import org.springframework.web.socket.WebSocketSession;
import org.springframework.web.socket.handler.AbstractWebSocketHandler;
public class WebSocketTest extends AbstractWebSocketHandler {
private static Logger logger = LoggerFactory.getLogger(WebSocketTest.class);
#Override
protected void handleTextMessage(WebSocketSession session, TextMessage message) throws Exception {
logger.debug("Recieved websocket message: " + message);
session.sendMessage(new TextMessage("thanks"));
}
#Override
public void afterConnectionEstablished(WebSocketSession session) throws Exception {
logger.info("WebSocket connection established!");
}
#Override
public void afterConnectionClosed(WebSocketSession session, CloseStatus status) throws Exception {
logger.info("WebSocket connection closed!");
}
}
Configuration(websocket.spring.xml):
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:websocket="http://www.springframework.org/schema/websocket"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans.xsd
http://www.springframework.org/schema/websocket
http://www.springframework.org/schema/websocket/spring-websocket.xsd">
<websocket:handlers>
<websocket:mapping path="/socket" handler="webSocketHandler"/>
</websocket:handlers>
<bean id="webSocketHandler" class="com.test.websocket.WebSocketTest"/>
</beans>
Servlet mapping is at /websocket/*
From the log It seems like the spring-websocket is initialized successfully however I'm getting this error, when I try to connect to the websocket.
Servlet.service() for servlet [spring-websocket] in context with path [] threw exception [Request processing failed; nested exception is org.springframework.web.socket.server.HandshakeFailureException: Uncaught failure for request http://localhost:9876/websocket/socket; nested exception is java.lang.IllegalArgumentException: No 'javax.websocket.server.ServerContainer' ServletContext attribute. Are you running in a Servlet container that supports JSR-356?] with root cause
Dependencies are: tomcat-embed-core, tomcat-embed-websocket, tomcat-juli and because of (Spring websocket example - error - Are you running in a Servlet container that supports J SR-356?) javax.websocket-api and tomcat-websocket
What am I missing?
Thanks in advance!
Maybe i found a solution to your problem.
You need to use WsSci servlet container initializer to the embedded tomcat context:
context.addServletContainerInitializer(new WsSci(), null);
https://github.com/spring-projects/spring-boot/issues/439

JAX-RS With Embedded Jetty Service - Home URL

I have downloaded a tutorial and modified it a little to suit my needs (added maven)
I was just wondering what makes the service start at a particular home page - when i run my service it defaults to the following
http://localhost:8080/RESTfulExample/WEB-INF/classes/com/ricki/test/JettyService.java
My web.xml looks as follows
<web-app id="WebApp_ID" version="2.4"
xmlns="http://java.sun.com/xml/ns/j2ee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee
http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd">
<display-name>Restful Web Application</display-name>
<servlet>
<servlet-name>jersey-serlvet</servlet-name>
<servlet-class>org.glassfish.jersey.servlet.ServletContainer</servlet-class>
<init-param>
<param-name>jersey.config.server.provider.packages</param-name>
<param-value>com.ricki.test</param-value>
</init-param>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>jersey-serlvet</servlet-name>
<url-pattern>/rest/*</url-pattern>
</servlet-mapping>
</web-app>
My jetty service class looks like this
import com.google.common.util.concurrent.AbstractIdleService;
import java.lang.management.ManagementFactory;
import org.eclipse.jetty.jmx.MBeanContainer;
import org.eclipse.jetty.server.Server;
import org.eclipse.jetty.util.resource.Resource;
import org.eclipse.jetty.webapp.WebAppContext;
public class JettyService extends AbstractIdleService
{
private Server server;
#Override
protected void startUp() throws Exception
{
server = new Server(8080);
MBeanContainer mbContainer = new MBeanContainer(ManagementFactory.getPlatformMBeanServer());
server.addBean(mbContainer);
Resource resource = Resource.newClassPathResource("/webapp");
WebAppContext context = new WebAppContext(resource.getURL().toExternalForm(), "/ricki-test/");
server.setHandler(context);
server.start();
}
#Override
protected void shutDown() throws Exception
{
try
{
server.stop();
server.join();
}
finally
{
server.destroy();
}
}
}
Any my rest class looks as follows
#Path("/hello")
public class HelloWorldService
{
private final Logger logger = Logger.getLogger(HelloWorldService.class);
#GET
#Path("/{param}")
public Response getMsg(#PathParam("param") String msg)
{
logger.info("Received message " + msg);
String output = "Hi : " + msg;
return Response.status(200).entity(output).build();
}
}
Ideall my homepage would be set to http://localhost:8080/RESTfulExample/ whcih displays my home page or in fact http://localhost:8080/RESTfulExample/rest/hello/ricki which allows me to interact with my service.
Thanks for your time.
There is no need to use a web.xml file if you don't want to. If you are using an embedded Jetty server, you can do the wireing to Jersey manually:
public static void main(String[] args) throws Exception {
ServletContextHandler context = new ServletContextHandler(ServletContextHandler.SESSIONS);
context.setContextPath("/");
Server jettyServer = new Server(8080);
jettyServer.setHandler(context);
ServletHolder jerseyServlet = context.addServlet(
org.glassfish.jersey.servlet.ServletContainer.class, "/*");
jerseyServlet.setInitOrder(0);
// Tells the Jersey Servlet which REST service/class to load.
jerseyServlet.setInitParameter(
"jersey.config.server.provider.classnames",
EntryPoint.class.getCanonicalName());
try {
jettyServer.start();
jettyServer.join();
} finally {
jettyServer.destroy();
}
}
Example from: http://www.nikgrozev.org/2014/10/16/rest-with-embedded-jetty-and-jersey-in-a-single-jar-step-by-step/
You can also use the jersey-container-jetty-http dependency:
<dependency>
<groupId>org.glassfish.jersey.containers</groupId>
<artifactId>jersey-container-jetty-http</artifactId>
<version>2.23.1</version>
</dependency>
This allows you to do:
URI baseUri = UriBuilder.fromUri("http://localhost/").port(9998).build();
ResourceConfig config = new ResourceConfig(MyResource.class);
Server server = JettyHttpContainerFactory.createServer(baseUri, config);
If you really want to use web.xml, you should access it in a different fashion:
Server server = new Server(8080);
String rootPath = SimplestServer.class.getClassLoader().getResource(".").toString();
WebAppContext webapp = new WebAppContext(rootPath + "../../src/main/webapp", "");
server.setHandler(webapp);
server.start();
server.join();
See also: Configure embedded jetty with web.xml?
At that point, it is easier to use the Jetty maven plugin, which bundles your war file and deploys it to a local Jetty server:
<plugin>
<groupId>org.eclipse.jetty</groupId>
<artifactId>jetty-maven-plugin</artifactId>
<version>9.3.6.v20151106</version>
<configuration>
<scanTargets>
<scanTarget>${project.basedir}/src/main</scanTarget>
<scanTarget>${project.basedir}/src/test</scanTarget>
</scanTargets>
<webAppConfig>
<contextPath>/${project.artifactId}-${project.version}</contextPath>
</webAppConfig>
<contextPath>${project.artifactId}</contextPath>
</configuration>
</plugin>

Why I am getting ClassCastException when accessing EJB 2.1 in Wildfly 8.2.1?

I am working with Java 1.7, XDoclet 1.2.3, WildFly 8.2.1.Final, Dynamic Web Module 2.5, EJB 2.1 in Eclipse Luna.
I have an Enterprise Application project named P001_EAR.
I have a Dynamic Web Project named P001_WAR.
I have a EJB Project named P001_EJB.
I have a EJB Client Project named P001_EJBClient.
In P001_EJB I create a XDoclet Stateless Session Bean (EJB 2.1).
This is its remote interface:
package com.p001.ejb;
/**
* Remote interface for Test1SLB.
* #generated
* #wtp generated
*/
public interface Test1SLB extends javax.ejb.EJBObject
{
/**
* <!-- begin-xdoclet-definition -->
* #generated //TODO: Must provide implementation for bean method stub */
public java.lang.String foo( java.lang.String param )
throws java.rmi.RemoteException;
}
This is its home interface:
package com.p001.ejb;
/**
* Home interface for Test1SLB.
* #generated
* #wtp generated
*/
public interface Test1SLBHome extends javax.ejb.EJBHome
{
public static final String COMP_NAME="java:comp/env/ejb/Test1SLB";
public static final String JNDI_NAME="Test1SLB";
public com.p001.ejb.Test1SLB create()
throws javax.ejb.CreateException,java.rmi.RemoteException;
}
In P001_WAR I created a Listener class named P001Listener; In its contextInitialized method I am trying to call foo method of Test1SLB EJB. This is its code:
public class P001Listener implements ServletContextListener {
public P001Listener() {
}
public void contextInitialized(ServletContextEvent sce) {
System.out.println("P001Listener.java: contextInitialized(ServletContextEvent sce): inside");
String test1SLBJNDIName = null;
Class test1SLBHomeClass = null;
InitialContext initialContext = null;
Object namedObject = null;
Object ejbHomeObject = null;
Test1SLBHome test1SLBHome = null;
Test1SLB test1SLB = null;
String rtnValue = null;
try {
test1SLBJNDIName = "java:global/P001_EAR/P001_EJB/Test1SLB!com.p001.ejb.Test1SLB";
System.out.println("P001Listener.java: contextInitialized(ServletContextEvent sce): test1SLBJNDIName=" + test1SLBJNDIName);
test1SLBHomeClass = Test1SLBHome.class;
System.out.println("P001Listener.java: contextInitialized(ServletContextEvent sce): test1SLBHomeClass=" + test1SLBHomeClass);
initialContext = new InitialContext();
System.out.println("P001Listener.java: contextInitialized(ServletContextEvent sce): initialContext=" + initialContext);
namedObject = initialContext.lookup(test1SLBJNDIName);
System.out.println("P001Listener.java: contextInitialized(ServletContextEvent sce): namedObject=" + namedObject);
ejbHomeObject = PortableRemoteObject.narrow(namedObject, test1SLBHomeClass);
System.out.println("P001Listener.java: contextInitialized(ServletContextEvent sce): ejbHomeObject=" + ejbHomeObject);
test1SLBHome = (Test1SLBHome) ejbHomeObject;
System.out.println("P001Listener.java: contextInitialized(ServletContextEvent sce): test1SLBHome=" + test1SLBHome);
test1SLB = test1SLBHome.create();
System.out.println("P001Listener.java: contextInitialized(ServletContextEvent sce): test1SLB=" + test1SLB);
rtnValue = test1SLB.foo("pagal");
System.out.println("P001Listener.java: contextInitialized(ServletContextEvent sce): rtnValue=" + rtnValue);
} catch (NamingException ne) {
ne.printStackTrace();
} catch (ClassCastException cce) {
cce.printStackTrace();
} catch (RemoteException re) {
re.printStackTrace();
} catch (CreateException ce) {
ce.printStackTrace();
}
}
public void contextDestroyed(ServletContextEvent sce) {
System.out.println("P001Listener.java: contextDestroyed(ServletContextEvent sce): inside");
}
}
I deploy the P001_EAR on WildFly. This is how the deployment looks:
P001_EAR.ear
Inside P001_EAR.ear I have:
META-INF
P001_EJB.jar
P001_WAR.war
P001_EJBClient.jar
Inside META-INF I have:
application.xml
Inside P001_EJB.jar I have:
META-INF\ejb-jar.xml
META-INF\jboss.xml
META-INF\MANIFEST.MF
com\p001\ejb\Test1SLBBean.class
com\p001\ejb\Test1SLBSession.class
Inside P001_WAR.war I have:
META-INF\MANIFEST.MF
WEB-INF\web.xml
WEB-INF\classes\com\p001\listener\P001Listener.class
WEB-INF\lib
Inside P001_EJBClient.jar I have:
META-INF\MANIFEST.MF
com\p001\ejb\Test1SLB.class
com\p001\ejb\Test1SLBHome.class
com\p001\ejb\Test1SLBLocal.class
com\p001\ejb\Test1SLBLocalHome.class
com\p001\ejb\Test1SLBUtil.class
I ran WildFly. In the server.log file I see that the EJB is deployed successfully:
2015-12-08 11:21:58,671 INFO
[org.jboss.as.ejb3.deployment.processors.EjbJndiBindingsDeploymentUnitProcessor]
(MSC service thread 1-3) JNDI bindings for session bean named Test1SLB
in deployment unit subdeployment "P001_EJB.jar" of deployment
"P001_EAR.ear" are as follows:
java:global/P001_EAR/P001_EJB/Test1SLB!com.p001.ejb.Test1SLBHome
java:app/P001_EJB/Test1SLB!com.p001.ejb.Test1SLBHome
java:module/Test1SLB!com.p001.ejb.Test1SLBHome
java:jboss/exported/P001_EAR/P001_EJB/Test1SLB!com.p001.ejb.Test1SLBHome
java:global/P001_EAR/P001_EJB/Test1SLB!com.p001.ejb.Test1SLBLocalHome
java:app/P001_EJB/Test1SLB!com.p001.ejb.Test1SLBLocalHome
java:module/Test1SLB!com.p001.ejb.Test1SLBLocalHome
java:global/P001_EAR/P001_EJB/Test1SLB!com.p001.ejb.Test1SLB
java:app/P001_EJB/Test1SLB!com.p001.ejb.Test1SLB
java:module/Test1SLB!com.p001.ejb.Test1SLB
java:jboss/exported/P001_EAR/P001_EJB/Test1SLB!com.p001.ejb.Test1SLB
java:global/P001_EAR/P001_EJB/Test1SLB!com.p001.ejb.Test1SLBLocal
java:app/P001_EJB/Test1SLB!com.p001.ejb.Test1SLBLocal
java:module/Test1SLB!com.p001.ejb.Test1SLBLocal
But I get java.lang.ClassCastException on this line:
ejbHomeObject = PortableRemoteObject.narrow(namedObject, test1SLBHomeClass);
This is the server.log:
2015-12-08 11:21:59,158 INFO [stdout] (MSC service thread 1-9)
P001Listener.java: contextInitialized(ServletContextEvent sce): inside
2015-12-08 11:21:59,159 INFO [stdout] (MSC service thread 1-9)
P001Listener.java: contextInitialized(ServletContextEvent sce):
test1SLBJNDIName=java:global/P001_EAR/P001_EJB/Test1SLB!com.p001.ejb.Test1SLB
2015-12-08 11:21:59,161 INFO [stdout] (MSC service thread 1-9)
P001Listener.java: contextInitialized(ServletContextEvent sce):
test1SLBHomeClass=interface com.p001.ejb.Test1SLBHome
2015-12-08 11:21:59,164 INFO [stdout] (MSC service thread 1-9)
P001Listener.java: contextInitialized(ServletContextEvent sce):
initialContext=javax.naming.InitialContext#2db02a6a
2015-12-08 11:21:59,171 INFO [org.jboss.ejb.client] (MSC service
thread 1-9) JBoss EJB Client version 2.0.1.Final 2015-12-08
11:21:59,177 INFO [stdout] (MSC service thread 1-9)
P001Listener.java: contextInitialized(ServletContextEvent sce):
namedObject=Proxy for remote EJB
StatelessEJBLocator{appName='P001_EAR', moduleName='P001_EJB',
distinctName='', beanName='Test1SLB', view='interface
com.p001.ejb.Test1SLB'}
2015-12-08 11:21:59,197 ERROR [stderr] (MSC service thread 1-9)
java.lang.ClassCastException
2015-12-08 11:21:59,198 ERROR [stderr] (MSC service thread 1-9) at
org.jboss.com.sun.corba.se.impl.javax.rmi.PortableRemoteObject.narrow(PortableRemoteObject.java:246)
2015-12-08 11:21:59,200 ERROR [stderr] (MSC service thread 1-9) at
javax.rmi.PortableRemoteObject.narrow(PortableRemoteObject.java:158)
2015-12-08 11:21:59,201 ERROR [stderr] (MSC service thread 1-9) at
com.p001.listener.P001Listener.contextInitialized(P001Listener.java:59)
2015-12-08 11:21:59,202 ERROR [stderr] (MSC service thread 1-9) at
io.undertow.servlet.core.ApplicationListeners.contextInitialized(ApplicationListeners.java:173)
2015-12-08 11:21:59,204 ERROR [stderr] (MSC service thread 1-9) at
io.undertow.servlet.core.DeploymentManagerImpl.deploy(DeploymentManagerImpl.java:194)
2015-12-08 11:21:59,206 ERROR [stderr] (MSC service thread 1-9) at
org.wildfly.extension.undertow.deployment.UndertowDeploymentService.startContext(UndertowDeploymentService.java:87)
2015-12-08 11:21:59,208 ERROR [stderr] (MSC service thread 1-9) at
org.wildfly.extension.undertow.deployment.UndertowDeploymentService.start(UndertowDeploymentService.java:72)
2015-12-08 11:21:59,210 ERROR [stderr] (MSC service thread 1-9) at
org.jboss.msc.service.ServiceControllerImpl$StartTask.startService(ServiceControllerImpl.java:1948)
2015-12-08 11:21:59,211 ERROR [stderr] (MSC service thread 1-9) at
org.jboss.msc.service.ServiceControllerImpl$StartTask.run(ServiceControllerImpl.java:1881)
2015-12-08 11:21:59,212 ERROR [stderr] (MSC service thread 1-9) at
java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)
2015-12-08 11:21:59,214 ERROR [stderr] (MSC service thread 1-9) at
java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615)
2015-12-08 11:21:59,215 ERROR [stderr] (MSC service thread 1-9) at
java.lang.Thread.run(Thread.java:745)
2015-12-08 11:21:59,216 ERROR [stderr] (MSC service thread 1-9) Caused
by: java.lang.ClassCastException: com.sun.proxy.$Proxy21 cannot be
cast to org.omg.CORBA.Object
2015-12-08 11:21:59,218 ERROR [stderr] (MSC service thread 1-9) at
org.jboss.com.sun.corba.se.impl.javax.rmi.PortableRemoteObject.narrow(PortableRemoteObject.java:225)
2015-12-08 11:21:59,219 ERROR [stderr] (MSC service thread 1-9) ...
11 more
What I am doing wrong to get this error message?
Thanks
UPDATE
I have found a solution. When I change this code:
test1SLBJNDIName = "java:global/P001_EAR/P001_EJB/Test1SLB!com.p001.ejb.Test1SLB";
to this code:
test1SLBJNDIName = "java:global/P001_EAR/P001_EJB/Test1SLB!com.p001.ejb.Test1SLBHome";
then it worked. So basically I am now looking up JNDI Name of Home and then casting it to Home Class.
In the old JBoss 4.2.X, I look up the JNDI Name Test1SLB and then cast it to Home Class and it worked. So was there 1 JNDI Name Test1SLB used for both Remote and Home in the old JBoss 4.2.X?
I have found a solution. When I change this code:
test1SLBJNDIName = "java:global/P001_EAR/P001_EJB/Test1SLB!com.p001.ejb.Test1SLB";
to this code:
test1SLBJNDIName = "java:global/P001_EAR/P001_EJB/Test1SLB!com.p001.ejb.Test1SLBHome";
then it worked. So basically I am now looking up Home and then casting it to Home Class.
In the old JBoss 4.2.X, I look up the JNDI Name Test1SLB and then cast it to Home Class and it worked. So there was 1 JNDI Name Test1SLB used for both Remote and Home in the old JBoss 4.2.X.

Shutting down Spring application makes JNDI name for datasource go away from jdbc context

I'm trying to setup a web application using Spring MVC and Spring Data JPA on my Weblogic
server. The application works fine the first time I deploy it to the Weblogic server but when I stop the application the jndi name (jdbc/myDS) to my datasource disappears from the JNDI Tree on my Weblogic server, and then when I try to start the application again I get the following error:
Caused By: javax.naming.NameNotFoundException: Unable to resolve 'jdbc.myDS'. Resolved 'jdbc'; remaining name 'myDS'
I'm setting up the following at startup in JPAConfiguratation.java:
package mySpringApp.application;
import java.util.Properties;
import javax.annotation.Resource;
import javax.naming.Context;
import javax.naming.InitialContext;
import javax.naming.NamingException;
import javax.sql.DataSource;
import org.apache.commons.dbcp.BasicDataSource;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.ImportResource;
import org.springframework.context.annotation.PropertySource;
import org.springframework.core.env.Environment;
import org.springframework.data.jpa.repository.config.EnableJpaRepositories;
import org.springframework.orm.jpa.JpaTransactionManager;
import org.springframework.orm.jpa.JpaVendorAdapter;
import org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean;
import org.springframework.orm.jpa.vendor.HibernateJpaVendorAdapter;
import org.springframework.transaction.annotation.EnableTransactionManagement;
/**
* An application context Java configuration class. The usage of Java configuration
* requires Spring Framework 3.0 or higher with following exceptions:
* <ul>
* <li>#EnableWebMvc annotation requires Spring Framework 3.1</li>
* </ul>
*/
#Configuration
#EnableJpaRepositories
#EnableTransactionManagement
#ImportResource("classpath:applicationContext.xml")
#PropertySource("classpath:application.properties")
public class JPAConfiguration{
private static final Logger logger = LoggerFactory.getLogger(JPAConfiguration.class);
private static final String PROPERTY_NAME_HIBERNATE_DIALECT = "hibernate.dialect";
private static final String PROPERTY_NAME_HIBERNATE_FORMAT_SQL = "hibernate.format_sql";
private static final String PROPERTY_NAME_HIBERNATE_NAMING_STRATEGY = "hibernate.ejb.naming_strategy";
private static final String PROPERTY_NAME_HIBERNATE_SHOW_SQL = "hibernate.show_sql";
private static final String PROPERTY_NAME_ENTITYMANAGER_PACKAGES_TO_SCAN = "entitymanager.packages.to.scan";
#Resource
private Environment environment;
#Bean
public DataSource dataSource() throws NamingException {
Context ctx = new InitialContext();
String jndiName = "jdbc/myDS";
DataSource dataSourceJNDINAME = (DataSource) ctx.lookup(jndiName);
return dataSourceJNDINAME;
));
#Bean
public JpaTransactionManager transactionManager() throws ClassNotFoundException {
JpaTransactionManager transactionManager = new JpaTransactionManager();
transactionManager.setEntityManagerFactory(entityManagerFactoryBean().getObject());
return transactionManager;
}
#Bean
public LocalContainerEntityManagerFactoryBean entityManagerFactoryBean() throws ClassNotFoundException {
LocalContainerEntityManagerFactoryBean entityManagerFactoryBean = new LocalContainerEntityManagerFactoryBean();
try {
entityManagerFactoryBean.setDataSource(dataSource());
} catch (Exception e) {
// TODO Auto-generated catch block
logger.error("Error setting datasource for entityManagerFactoryBean", e);
logger.error(e.getMessage());
}
entityManagerFactoryBean.setPackagesToScan(environment.getRequiredProperty(PROPERTY_NAME_ENTITYMANAGER_PACKAGES_TO_SCAN));
JpaVendorAdapter vendorAdapter = new HibernateJpaVendorAdapter();
entityManagerFactoryBean.setJpaVendorAdapter(vendorAdapter);
Properties jpaProterties = new Properties();
jpaProterties.put(PROPERTY_NAME_HIBERNATE_DIALECT, environment.getRequiredProperty(PROPERTY_NAME_HIBERNATE_DIALECT));
jpaProterties.put(PROPERTY_NAME_HIBERNATE_FORMAT_SQL, environment.getRequiredProperty(PROPERTY_NAME_HIBERNATE_FORMAT_SQL));
jpaProterties.put(PROPERTY_NAME_HIBERNATE_NAMING_STRATEGY, environment.getRequiredProperty(PROPERTY_NAME_HIBERNATE_NAMING_STRATEGY));
jpaProterties.put(PROPERTY_NAME_HIBERNATE_SHOW_SQL, environment.getRequiredProperty(PROPERTY_NAME_HIBERNATE_SHOW_SQL));
entityManagerFactoryBean.setJpaProperties(jpaProterties);
return entityManagerFactoryBean;
}
Web.xml:
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns="http://java.sun.com/xml/ns/javaee"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"
version="2.5">
<servlet>
<servlet-name>MySpringApp</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
<init-param>
<param-name>contextClass</param-name>
<param-value>org.springframework.web.context.support.AnnotationConfigWebApplicationContext</param-value>
</init-param>
<init-param>
<param-name>contextConfigLocation</param-name>
<param-value>mySpringApp.application</param-value>
</init-param>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>MySpringApp</servlet-name>
<url-pattern>/</url-pattern>
</servlet-mapping>
</web-app>
The log output when shutting down the application the first time:
INFO - onfigWebApplicationContext - Closing WebApplicationContext for namespace 'MySpringApp-servlet': startup date [Thu Oct 03 13:13:05 CEST 2013]; root of context hierarchy
DEBUG - DefaultListableBeanFactory - Returning cached instance of singleton bean 'lifecycleProcessor'
INFO - DefaultListableBeanFactory - Destroying singletons in org.springframework.beans.factory.support.DefaultListableBeanFactory#1c51f5cb: defining beans [org.springframework.context.annotation.internalConfigurationAnnotationProcesso
r,org.springframework.context.annotation.internalAutowiredAnnotationProcessor,org.springframework.context.annotation.internalRequiredAnnotationProcessor,org.springframework.context.annotation.internalCommonAnnotationProcessor,org.sprin
gframework.context.annotation.internalPersistenceAnnotationProcessor,webConfig,JPAConfiguration,org.springframework.context.annotation.ConfigurationClassPostProcessor.importAwareProcessor,homeController,firstController,buildController,
greetingController,repositoryBuildService,org.springframework.data.repository.core.support.RepositoryInterfaceAwareBeanPostProcessor#0,org.springframework.aop.config.internalAutoProxyCreator,org.springframework.data.repository.core.sup
port.RepositoryInterfaceAwareBeanPostProcessor#1,org.springframework.web.servlet.config.annotation.DelegatingWebMvcConfiguration,requestMappingHandlerMapping,mvcContentNegotiationManager,viewControllerHandlerMapping,beanNameHandlerMapp
ing,resourceHandlerMapping,defaultServletHandlerMapping,requestMappingHandlerAdapter,mvcConversionService,mvcValidator,httpRequestHandlerAdapter,simpleControllerHandlerAdapter,handlerExceptionResolver,messageSource,viewResolver,org.spr
ingframework.web.servlet.resource.ResourceHttpRequestHandler#0,org.springframework.web.servlet.handler.SimpleUrlHandlerMapping#0,org.springframework.web.servlet.handler.BeanNameUrlHandlerMapping,org.springframework.web.servlet.mvc.Http
RequestHandlerAdapter,org.springframework.web.servlet.mvc.SimpleControllerHandlerAdapter,org.springframework.web.servlet.resource.DefaultServletHttpRequestHandler#0,org.springframework.web.servlet.handler.SimpleUrlHandlerMapping#1,buil
dRepository,org.springframework.data.repository.core.support.RepositoryInterfaceAwareBeanPostProcessor#2,org.springframework.transaction.annotation.ProxyTransactionManagementConfiguration,org.springframework.transaction.config.internal
TransactionAdvisor,transactionAttributeSource,transactionInterceptor,dataSource,transactionManager,entityManagerFactoryBean,org.springframework.web.servlet.resource.ResourceHttpRequestHandler#1,org.springframework.web.servlet.handler.S
impleUrlHandlerMapping#2,org.springframework.web.servlet.resource.DefaultServletHttpRequestHandler#1,org.springframework.web.servlet.handler.SimpleUrlHandlerMapping#3,org.springframework.data.repository.core.support.RepositoryInterface
AwareBeanPostProcessor#3]; root of factory hierarchy
DEBUG - DisposableBeanAdapter - Invoking destroy() on bean with name 'org.springframework.web.servlet.config.annotation.DelegatingWebMvcConfiguration'
DEBUG - DefaultListableBeanFactory - Retrieved dependent beans for bean '(inner bean)': [(inner bean), buildRepository]
DEBUG - DisposableBeanAdapter - Invoking destroy() on bean with name 'entityManagerFactoryBean'
INFO - erEntityManagerFactoryBean - Closing JPA EntityManagerFactory for persistence unit 'mySpringAppPersistenceUnit'
DEBUG - SessionFactoryImpl - HHH000031: Closing
DEBUG - tityManagerFactoryRegistry - Remove: name=mySpringAppPersistenceUnit
DEBUG - DisposableBeanAdapter - Invoking destroy method 'shutdown' on bean with name 'dataSource'
DEBUG - DisposableBeanAdapter - Invoking destroy() on bean with name 'JPAConfiguration'
DEBUG - DisposableBeanAdapter - Invoking destroy() on bean with name 'webConfig'
DEBUG - DisposableBeanAdapter - Invoking destroy() on bean with name 'org.springframework.transaction.annotation.ProxyTransactionManagementConfiguration'
I'm using:
Spring 3.2.4.RELEASE
Hibernate 4.2.6.Final
Weblogic 10.3.5
Do I need to handle the shutdown of the application manually somehow? What can cause the jndi name disappear from the server context?
All help is greatly appreciated!
I had the same problem. Adding destroyMethod="" fixed it for me.
Apparently if there is no destroyMethod, Spring tries to determine what the destroy method is. This is apparently causing the datasource to be closed and the JNDI key to be removed from the tree. Changing it to "" forces it to not look for a destroyMethod.
#Bean(destroyMethod = "")
public DataSource dataSource() throws NamingException{
Context context = new InitialContext();
return (DataSource)context.lookup("jdbc.mydatasource");
}

How to use EJB 3.1 DI in Servlet ? (Could not inject session bean by #EJB from web application)

I am tying to merging web application(gwt, jpa) to an separate 2 application(business login in ejb/jpa and web client in gwt). Currently i can`t inject my beans from web application (simple servlet)
I am using glassfish v3.
module limbo(ejb jar) is in dependency of module lust (war).
If I use lust with compiler output of limbo everything work perfect (if ejb in web application and the are deploying together as one application).
Have I messed some container configuration ?
Here is my steps:
I have some limbo.jar (ejb-jar) deployed to ejb container. I do not use any ejb-jar.xml, only annotations.
package ua.co.inferno.limbo.persistence.beans;
import javax.ejb.Remote;
#Remote
public interface IPersistentServiceRemote {
ArrayList<String> getTerminalACPList();
ArrayList<String> getBoxACPList();
ArrayList<String> getCNPList();
ArrayList<String> getCNSList();
String getProductNamebyID(int boxid);
ArrayList<String> getRegionsList(String lang);
long getSequence();
void persistEntity (Object ent);
}
package ua.co.inferno.limbo.persistence.beans;
import ua.co.inferno.limbo.persistence.entitis.EsetChSchemaEntity;
import ua.co.inferno.limbo.persistence.entitis.EsetKeyActionsEntity;
#Local
public interface IPersistentService {
ArrayList<String> getTerminalACPList();
ArrayList<String> getBoxACPList();
ArrayList<String> getCNPList();
ArrayList<String> getCNSList();
String getProductNamebyID(int boxid);
ArrayList<String> getRegionsList(String lang);
long getSequence();
long persistPurchaseBox(EsetRegPurchaserEntity rp);
void removePurchaseTempBox(EsetRegPurchaserTempEntity rpt);
EsetRegionsEntity getRegionsById(long rid);
void persistEntity (Object ent);
}
package ua.co.inferno.limbo.persistence.beans;
import ua.co.inferno.limbo.persistence.entitis.EsetChSchemaEntity;
import ua.co.inferno.limbo.persistence.entitis.EsetKeyActionsEntity;
import ua.co.inferno.limbo.persistence.entitis.EsetRegBoxesEntity;
import javax.ejb.Stateless;
import javax.persistence.EntityManager;
import javax.persistence.PersistenceContext;
#Stateless(name = "PersistentService")
public class PersistentServiceEJB
implements
IPersistentService, IPersistentServiceRemote{
#PersistenceContext(unitName = "Limbo")
EntityManager em;
public PersistentServiceEJB() {
}
.........
}
Than i trying to use PersistentService session bean(included in limbo.jar) from web application in lust.war (the limbo.jar & lust.war is not in ear)
package ua.co.lust;
import ua.co.inferno.limbo.persistence.beans.IPersistentService;
import javax.ejb.EJB;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
#WebServlet(name = "ServletTest",
urlPatterns = {"/"})
public class ServletTest extends HttpServlet {
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
service(request, response);
}
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
service(request, response);
}
#EJB
private IPersistentService pService;
public void service(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
String hi = pService.getCNPList().toString();
System.out.println("testBean.hello method returned: " + hi);
System.out.println("In MyServlet::init()");
System.out.println("all regions" + pService.getRegionsList("ua"));
System.out.println("all regions" + pService.getBoxACPList());
}
}
web.xm
<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns="http://java.sun.com/xml/ns/javaee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee
http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd"
version="3.0">
<servlet>
<servlet-name>ServletTest</servlet-name>
<servlet-class>ua.co.lust.ServletTest</servlet-class>
</servlet>
</web-app>
When servelt is loading i ge 404 eror (The requested resource () is not available.)
And errors in logs :
global
Log Level
SEVERE
Logger
global
Name-Value Pairs
{_ThreadName=Thread-1, _ThreadID=31}
Record Number
1421
Message ID
Complete Message
Class [ Lua/co/inferno/limbo/persistence/beans/IPersistentService; ] not found. Error while loading [ class ua.co.lust.ServletTest ]
javax.enterprise.system.tools.deployment.org.glassfish.deployment.common
Log Level
WARNING
Logger
javax.enterprise.system.tools.deployment.org.glassfish.deployment.common
Name-Value Pairs
{_ThreadName=Thread-1, _ThreadID=31}
Record Number
1422
Message ID
Error in annotation processing
Complete Message
java.lang.NoClassDefFoundError: Lua/co/inferno/limbo/persistence/beans/IPersistentService;
ejb jar was deployed with this info log :
Log Level
INFO
Logger
javax.enterprise.system.container.ejb.com.sun.ejb.containers
Name-Value Pairs
{_ThreadName=Thread-1, _ThreadID=26}
Record Number
1436
Message ID
Glassfish-specific (Non-portable) JNDI names for EJB PersistentService
Complete Message
[ua.co.inferno.limbo.persistence.beans.IPersistentServiceRemote#ua.co.inferno.limbo.persistence.beans.IPersistentServiceRemote, ua.co.inferno.limbo.persistence.beans.IPersistentServiceRemote]
Log Level
INFO
Logger
javax.enterprise.system.tools.admin.org.glassfish.deployment.admin
Name-Value Pairs
{_ThreadName=Thread-1, _ThreadID=26}
Record Number
1445
Message ID
Complete Message
limbo was successfully deployed in 610 milliseconds.
Do i nee to add some additional configuration in a case of injections from others application?
Some ideas?
in a case of #Remote
package ua.co.lust;
import ua.co.inferno.limbo.persistence.beans.PersistentServiceRemote;
import javax.naming.Context;
import javax.naming.InitialContext;
import javax.naming.NamingException;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
#WebServlet(name = "ServletTest",
urlPatterns = {"/"})
public class WebTestServlet extends HttpServlet {
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
service(request, response);
}
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
service(request, response);
}
// #EJB
// private PersistentServiceRemote pService; <<-- DI not working :( - same errs as with Local interface (class not found)
public void service(HttpServletRequest request, HttpServletResponse response) throws ServletException,
IOException {
Context ctx = null;
try {
ctx = new InitialContext();
PersistentServiceRemote pService =
(PersistentServiceRemote) ctx.lookup("java:global/limbo/PersistentServiceBean!ua.co.inferno.limbo.persistence.beans.PersistentServiceRemote");
String hi = pService.getCNPList().toString();
System.out.println("testBean.hello method returned: " + hi);
System.out.println("In MyServlet::init()");
System.out.println("all regions" + pService.getRegionsList("ua"));
System.out.println("all regions" + pService.getBoxACPList());
} catch (NamingException e) {
e.printStackTrace();
}
}
}
Log :
Log Level
SEVERE
Logger
javax.enterprise.system.std.com.sun.enterprise.v3.services.impl
Name-Value Pairs
{_ThreadName=Thread-1, _ThreadID=32}
Record Number
1963
Message ID
javax.naming.NamingException
Complete Message
Lookup failed for 'java:global/limbo/PersistentServiceBean!ua.co.inferno.limbo.persistence.beans.PersistentServiceRemote' in SerialContext [Root exception is javax.naming.NamingException: ejb ref resolution error for remote business
interfaceua.co.inferno.limbo.persistence.beans.PersistentServiceRemote [Root exception is java.lang.ClassNotFoundException: ua.co.inferno.limbo.persistence.beans.PersistentServiceRemote]] at com.sun.enterprise.naming.impl.SerialContext.lookup(SerialContext.java:442) at
javax.naming.InitialContext.lookup(InitialContext.java:392) at javax.naming.InitialContext.lookup(InitialContext.java:392) at
ua.co.lust.WebTestServlet.service(WebTestServlet.java:45) at javax.servlet.http.HttpServlet.service(HttpServlet.java:847) at org.apache.catalina.core.StandardWrapper.service(StandardWrapper.java:1523) at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:279) at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:188) at
org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:641) at com.sun.enterprise.web.WebPipeline.invoke(WebPipeline.java:97) at
com.sun.enterprise.web.PESessionLockingStandardPipeline.invoke(PESessionLockingStandardPipel
ine.java:85) at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:185) at
org.apache.catalina.connector.CoyoteAdapter.doService(CoyoteAdapter.java:332) at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:233) at com.sun.enterprise.v3.services.impl.ContainerMapper.service(ContainerMapper.java:165) at com.sun.grizzly.http.ProcessorTask.invokeAdapter(ProcessorTask.java:791) at
com.sun.grizzly.http.ProcessorTask.doProcess(ProcessorTask.java:693) at com.sun.grizzly.http.ProcessorTask.process(ProcessorTask.java:954) at
com.sun.grizzly.http.DefaultProtocolFilter.execute(DefaultProtocolFilter.java:170) at
com.sun.grizzly.DefaultProtocolChain.executeProtocolFilter(DefaultProtocolChain.java:135) at com.sun.grizzly.DefaultProtocolChain.execute(DefaultProtocolChain.java:102) at
com.sun.grizzly.DefaultProtocolChain.execute(DefaultProtocolChain.java:88) at
com.sun.grizzly.http.HttpProtocolChain.execute(HttpProtocolChain.java:76) at com.sun.grizzly.ProtocolChainContextTask.doCall(ProtocolChainContextTask.java:53) at com.sun.grizzly.SelectionKeyContextTask.call(SelectionKeyContextTask.java:57) at com.sun.grizzly.ContextTask.run(ContextTask.java:69) at com.sun.grizzly.util.AbstractThreadPool$Worker.doWork(AbstractThreadPool.java:330) at com.sun.grizzly.util.AbstractThreadPool$Worker.run(AbstractThreadPool.java:309) at java.lang.Thread.run(Thread.java:619) Caused by: javax.naming.NamingException: ejb ref resolution error for remote business interfaceua.co.inferno.limbo.persistence.beans.PersistentServiceRemote [Root exception is java.lang.ClassNotFoundException: ua.co.inferno.limbo.persistence.beans.PersistentServiceRemote] at com.sun.ejb.EJBUtils.lookupRemote30BusinessObject(EJBUtils.java:430) at
com.sun.ejb.containers.RemoteBusinessObjectFactory.getObjectInstance(RemoteBusinessObjectFac
tory.java:70) at javax.naming.spi.NamingManager.getObjectInstance(NamingManager.java:304) at
com.sun.enterprise.naming.impl.SerialContext.getObjectInstance(SerialContext.java:472) at com.sun.enterprise.naming.impl.SerialContext.lookup(SerialContext.java:437) ... 28 more
Caused by: java.lang.ClassNotFoundException: ua.co.inferno.limbo.persistence.beans.PersistentServiceRemote at java.net.URLClassLoader$1.run(URLClassLoader.java:200) at java.security.AccessController.doPrivileged(Native Method) at
java.net.URLClassLoader.findClass(URLClassLoader.java:188) at org.glassfish.web.loader.WebappClassLoader.findClass(WebappClassLoader.java:959) at
org.glassfish.web.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1430) at com.sun.ejb.EJBUtils.getBusinessIntfClassLoader(EJBUtils.java:678) at
com.sun.ejb.EJBUtils.loadGeneratedRemoteBusinessClasses(EJBUtils.java:459) at com.sun.ejb.EJBUtils.lookupRemote30BusinessObject(EJBUtils.java:410) ... 32 more
Info deploy log
Log Level
INFO
Logger
javax.enterprise.system.container.ejb.com.sun.ejb.containers
Name-Value Pairs
{_ThreadName=Thread-1, _ThreadID=11}
Record Number
1899
Message ID
Portable JNDI names for EJB PersistentServiceBean
Complete Message
[java:global/limbo/PersistentServiceBean!ua.co.inferno.limbo.persistence.beans.PersistentServiceRemote, java:global/limbo/PersistentServiceBean!ua.co.inferno.limbo.persistence.beans.PersistentServiceLocal]
Do I need include my ejb jar into WEB=INF/lib if I am using Remote business logic call?
Why DI not working in a case of remote?
and it work prefect if I include
compile output from limbo module and
provide :
PersistentServiceRemote pService =
(PersistentServiceRemote) ctx.lookup("java:global/lust/PersistentServiceBean!ua.co.inferno.limbo.persistence.beans.PersistentServiceRemote");
Why I couldn`t look up for the PersistentServiceRemote (Remote interface of PersistentServiceBean ) for another web application ?
By sample`s code from glassfish It should work (.
Any ideas?
Ok. So as Pascal said. We need to package remote interface in webapp. We can use Local interface injection in different application. If you need use Local interface you need to include ejb jar in your application. Current design - package remote interface to webapp
If you don't deploy your ejb-jar as a lib of your war (i.e. under WEB-INF/lib), I don't think you'll be able to use the Local interface (and you'll have to package the remote interface in your webapp).
PS: you don't really need the web.xml here.

Categories