Logo 
Search:

Java Forum

Ask Question   UnAnswered
Home » Forum » Java       RSS Feeds

spring + ejb3 not bound strange issue

  Asked By: Blowice    Date: May 17    Category: Java    Views: 2171
  

Hi there,

I've got a strange situation in my spring+ejb3 deployment under jboss5.0.1GA + IntelliJ IDEA 8.1.4.
every time i start jboss from IntelliJ, it will give me:
'ERROR [DispatcherServlet] Context initialization failed
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'pservice': Invocation of init method failed; nested exception is javax.naming.NameNotFoundException: ProductServiceImpl not bound ' error

springapp-servlet.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:jee="http://www.springframework.org/schema/jee"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-2.5.xsd http://www.springframework.org/schema/jeehttp://www.springframework.org/schema/jee/spring-jee-2.5.xsd">


<bean id="messageSource" class="org.springframework.context.support.ResourceBundleMessageSource">
<property name="basename" value="messages"/>
</bean>


<!-- the application context definition for the springapp DispatcherServlet -->


<jee:jndi-lookup id="pservice" jndi-name="ProductServiceImpl/remote"></jee:jndi-lookup>


<bean id="productManager" class="com.lab.productsystem.spring.bean.ProductManagerImpl">
<property name="pservice" ref="pservice"/>
</bean>


<bean id="viewResolver" class="org.springframework.web.servlet.view.InternalResourceViewResolver">
<property name="viewClass" value="org.springframework.web.servlet.view.JstlView"></property>
<property name="prefix" value="/WEB-INF/jsp/"></property>
<property name="suffix" value=".jsp"></property>
</bean>


<bean id="urlHandler"
class="org.springframework.web.servlet.handler.SimpleUrlHandlerMapping">
<property name="mappings">
<map>
<entry key="/listProduct.htm" value="productController"/>
<entry key="/editProduct.htm" value="productController"/>
</map>
</property>
</bean>

<bean id="productController"
class="com.lab.productsystem.spring.mvc.controller.ProductController">
<property name="methodNameResolver"
ref="productControllerResolver"/>
<property name="productManager" ref="productManager"/>
</bean>


<bean id="productControllerResolver"
class="org.springframework.web.servlet.mvc.multiaction.PropertiesMethodNameResolver">
<property name="mappings">
<props>
<prop key="/listProduct.htm">handleListProductRequest</prop>
<prop key="/editProduct.htm">handleUpdateProductRequest</prop>
</props>
</property>
</bean>

</beans>


session bean class
@Stateless
public class ProductServiceImpl implements ProductService{
@PersistenceContext
private EntityManager em;

public Product findById(int id) {
try {
Product product = em.find(Product.class, id);
return product;
} catch (Exception e) {
System.out.println(e);
return null;
}
}

public List<Product> findAll() {
try {
return em.createNamedQuery("Product.findAll").getResultList();
} catch (Exception e) {
System.out.println(e);
return null;
}
}
}

class to call this session bean service via JNDI lookup
public class ProductManagerImpl implements ProductManager{

private ProductService pservice; // inject me!!


public void setPservice(ProductService p){
this.pservice=p;
}


public Product getProduct(int id) {
return pservice.findById(id);
}


public List<Product> getProducts() {
return pservice.findAll();
}
}


the strange thing is, even though, the first time upon jboss startup it always says 'ProductServiceImpl not bound'. as soon as I deploy the project again via my IDE, the error just gone!! and the app runs perfect.



is there a way to get rid of this not bound error?

Thanks in advance.

Share: 

 

3 Answers Found

 
Answer #1    Answered By: Blowice Yang     Answered On: May 17

below is the jboss council upon first time start:

09:06:01,551 ERROR [DispatcherServlet] Context initialization failed
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'pservice': Invocation of init method failed; nested exception is javax.naming.NameNotFoundException: ProductServiceImpl not bound
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1337)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:473)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory$1.run(AbstractAutowireCapableBeanFactory.java:409)
at java.security.AccessController.doPrivileged(Native Method)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:380)
at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:264)
at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:221)
at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:261)
at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:185)
at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:164)
at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:423)
at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:729)
at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:381)
at org.springframework.web.servlet.FrameworkServlet.createWebApplicationContext(FrameworkServlet.java:402)
at org.springframework.web.servlet.FrameworkServlet.initWebApplicationContext(FrameworkServlet.java:316)
at org.springframework.web.servlet.FrameworkServlet.initServletBean(FrameworkServlet.java:282)
at org.springframework.web.servlet.HttpServletBean.init(HttpServletBean.java:126)
at javax.servlet.GenericServlet.init(GenericServlet.java:212)
at org.apache.catalina.core.StandardWrapper.loadServlet(StandardWrapper.java:1048)
at org.apache.catalina.core.StandardWrapper.load(StandardWrapper.java:950)
at org.apache.catalina.core.StandardContext.loadOnStartup(StandardContext.java:4122)
at org.apache.catalina.core.StandardContext.start(StandardContext.java:4421)
at
.....
[2011-05-18 09:06:01,584] Facet Web: Facet is deployed successfully
09:06:01,667 INFO [SessionFactoryObjectFactory] Factory name: persistence.unit:unitName=#PRODUCT-PU
09:06:01,669 INFO [NamingHelper] JNDI InitialContext properties:{java.naming.factory.initial=org.jnp.interfaces.NamingContextFactory, java.naming.factory.url.pkgs=org.jboss.naming:org.jnp.interfaces}
09:06:01,675 INFO [SessionFactoryObjectFactory] Bound factory to JNDI name: persistence.unit:unitName=#PRODUCT-PU
09:06:01,675 WARN [SessionFactoryObjectFactory] InitialContext did not implement EventContext
09:06:01,675 INFO [NamingHelper] JNDI InitialContext properties:{java.naming.factory.initial=org.jnp.interfaces.NamingContextFactory, java.naming.factory.url.pkgs=org.jboss.naming:org.jnp.interfaces}
09:06:02,079 INFO [SessionSpecContainer] Starting jboss.j2ee:jar=Product-EJB.jar,name=ProductServiceImpl,service=EJB3
09:06:02,099 INFO [EJBContainer] STARTED EJB: com.lab.productsystem.ejb.session.ProductServiceImpl ejbName: ProductServiceImpl
09:06:02,174 INFO [JndiSessionRegistrarBase] Binding the following Entries in Global JNDI:


ProductServiceImpl/remote - EJB3.x Default Remote Business Interface
ProductServiceImpl/remote-com.lab.productsystem.ejb.session.ProductService - EJB3.x Remote Business Interface


[2011-05-18 09:06:02,237] Facet EJB: Facet is deployed successfully

 
Answer #2    Answered By: Blowice Yang     Answered On: May 17

this is the jboss council after I redeploy via IntelliJ

[2011-05-18 09:24:59,628] Facet Web: Facet is being deployed, please wait...
[2011-05-18 09:24:59,628] Facet EJB: Facet is being deployed, please wait...
09:24:59,633 INFO [TomcatDeployment] undeploy, ctxPath=/Product-Web
09:24:59,641 INFO [SessionSpecContainer] Stopping jboss.j2ee:jar=Product-EJB.jar,name=ProductServiceImpl,service=EJB3
09:24:59,665 INFO [EJBContainer] STOPPED EJB: com.lab.productsystem.ejb.session.ProductServiceImpl ejbName: ProductServiceImpl
09:24:59,716 INFO [MainDeployer] deploy, url=file:/Users/jack/development/projects/ProductSystem/out/Product-Web.war
09:24:59,747 INFO [PersistenceUnitDeployment] Stopping persistence unit persistence.unit:unitName=#PRODUCT-PU
09:24:59,747 INFO [SessionFactoryImpl] closing
09:24:59,747 INFO [SessionFactoryObjectFactory] Unbinding factory from JNDI name: persistence.unit:unitName=#PRODUCT-PU
09:24:59,747 INFO [NamingHelper] JNDI InitialContext properties:{java.naming.factory.initial=org.jnp.interfaces.NamingContextFactory, java.naming.factory.url.pkgs=org.jboss.naming:org.jnp.interfaces}
09:24:59,747 INFO [SessionFactoryObjectFactory] Unbound factory from JNDI name: persistence.unit:unitName=#PRODUCT-PU
09:24:59,769 INFO [MainDeployer] deploy, url=file:/Users/jack/development/projects/ProductSystem/out/Product-EJB.jar
09:24:59,890 INFO [Ejb3DependenciesDeployer] Encountered deployment AbstractVFSDeploymentContext@15158153{vfszip:/Users/jack/development/projects/ProductSystem/out/Product-EJB.jar/}
09:24:59,890 INFO [Ejb3DependenciesDeployer] Encountered deployment AbstractVFSDeploymentContext@15158153{vfszip:/Users/jack/development/projects/ProductSystem/out/Product-EJB.jar/}
09:24:59,890 INFO [Ejb3DependenciesDeployer] Encountered deployment AbstractVFSDeploymentContext@15158153{vfszip:/Users/jack/development/projects/ProductSystem/out/Product-EJB.jar/}
09:24:59,890 INFO [Ejb3DependenciesDeployer] Encountered deployment AbstractVFSDeploymentContext@15158153{vfszip:/Users/jack/development/projects/ProductSystem/out/Product-EJB.jar/}
09:24:59,983 INFO [JBossASKernel] Created KernelDeployment for: Product-EJB.jar
09:24:59,983 INFO [JBossASKernel] installing bean: jboss.j2ee:jar=Product-EJB.jar,name=ProductServiceImpl,service=EJB3
09:24:59,984 INFO [JBossASKernel] with dependencies:
09:24:59,984 INFO [JBossASKernel] and demands:
09:24:59,984 INFO [JBossASKernel] jboss.ejb:service=EJBTimerService
09:24:59,984 INFO [JBossASKernel] persistence.unit:unitName=#PRODUCT-PU
09:24:59,984 INFO [JBossASKernel] and supplies:
09:24:59,984 INFO [JBossASKernel] Class:com.lab.productsystem.ejb.session.ProductService
09:24:59,984 INFO [JBossASKernel] jndi:ProductServiceImpl/remote
09:24:59,984 INFO [JBossASKernel] jndi:ProductServiceImpl/remote-com.lab.productsystem.ejb.session.ProductService
09:24:59,984 INFO [JBossASKernel] Added bean(jboss.j2ee:jar=Product-EJB.jar,name=ProductServiceImpl,service=EJB3) to KernelDeployment of: Product-EJB.jar
09:25:00,017 INFO [PersistenceUnitDeployment] Starting persistence unit persistence.unit:unitName=#PRODUCT-PU
09:25:00,020 WARN [Ejb3Configuration] Persistence provider caller does not implement the EJB3 spec correctly. PersistenceUnitInfo.getNewTempClassLoader() is null.
09:25:00,021 INFO [AnnotationBinder] Binding entity from annotated class: com.lab.productsystem.ejb.entity.Product
09:25:00,021 INFO [QueryBinder] Binding Named query: Product.findAll => SELECT p FROM Product p order by p.id asc
09:25:00,021 INFO [EntityBinder] Bind entity com.lab.productsystem.ejb.entity.Product on table product
09:25:00,035 INFO [HibernateSearchEventListenerRegister] Unable to find org.hibernate.search.event.FullTextIndexEventListener on the classpath. Hibernate Search is not enabled.
09:25:00,038 INFO [ConnectionProviderFactory] Initializing connection provider: org.hibernate.ejb.connection.InjectedDataSourceConnectionProvider
09:25:00,038 INFO [InjectedDataSourceConnectionProvider] Using provided datasource
09:25:00,038 INFO [SettingsFactory] RDBMS: MySQL, version: 5.1.57
09:25:00,039 INFO [SettingsFactory] JDBC driver: MySQL-AB JDBC Driver, version: mysql-connector-java-5.1.6 ( Revision: ${svn.Revision} )
09:25:00,039 INFO [Dialect] Using dialect: org.hibernate.dialect.MySQLDialect
09:25:00,040 INFO [TransactionFactoryFactory] Transaction strategy: org.hibernate.ejb.transaction.JoinableCMTTransactionFactory
09:25:00,040 INFO [TransactionManagerLookupFactory] instantiating TransactionManagerLookup: org.hibernate.transaction.JBossTransactionManagerLookup
09:25:00,041 INFO [TransactionManagerLookupFactory] instantiated TransactionManagerLookup
09:25:00,041 INFO [SettingsFactory] Automatic flush during beforeCompletion(): disabled
09:25:00,041 INFO [SettingsFactory] Automatic session close at end of transaction: disabled
09:25:00,041 INFO [SettingsFactory] JDBC batch size: 15
09:25:00,041 INFO [SettingsFactory] JDBC batch updates for versioned data: disabled
09:25:00,041 INFO [SettingsFactory] Scrollable result sets: enabled
09:25:00,041 INFO [SettingsFactory] JDBC3 getGeneratedKeys(): enabled
09:25:00,041 INFO [SettingsFactory] Connection release mode: auto
09:25:00,041 INFO [SettingsFactory] Maximum outer join fetch depth: 2
09:25:00,041 INFO [SettingsFactory] Default batch fetch size: 1
09:25:00,041 INFO [SettingsFactory] Generate SQL with comments: disabled
09:25:00,041 INFO [SettingsFactory] Order SQL updates by primary key: disabled
09:25:00,041 INFO [SettingsFactory] Order SQL inserts for batching: disabled
09:25:00,041 INFO [SettingsFactory] Query translator: org.hibernate.hql.ast.ASTQueryTranslatorFactory
09:25:00,042 INFO [ASTQueryTranslatorFactory] Using ASTQueryTranslatorFactory
09:25:00,042 INFO [SettingsFactory] Query language substitutions: {}
09:25:00,043 INFO [SettingsFactory] JPA-QL strict compliance: enabled
09:25:00,043 INFO [SettingsFactory] Second-level cache: enabled
09:25:00,043 INFO [SettingsFactory] Query cache: disabled
09:25:00,043 INFO [SettingsFactory] Cache region factory : org.hibernate.cache.impl.bridge.RegionFactoryCacheProviderBridge
09:25:00,043 INFO [RegionFactoryCacheProviderBridge] Cache provider: org.hibernate.cache.HashtableCacheProvider
09:25:00,044 INFO [SettingsFactory] Optimize cache for minimal puts: disabled
09:25:00,044 INFO [SettingsFactory] Cache region prefix: persistence.unit:unitName=#PRODUCT-PU
09:25:00,044 INFO [SettingsFactory] Structured second-level cache entries: disabled
09:25:00,044 INFO [SettingsFactory] Statistics: disabled
09:25:00,044 INFO [SettingsFactory] Deleted entity synthetic identifier rollback: disabled
09:25:00,044 INFO [SettingsFactory] Default entity-mode: pojo
09:25:00,044 INFO [SettingsFactory] Named query checking : enabled
09:25:00,065 INFO [SessionFactoryImpl] building session factory
09:25:00,080 INFO [SessionFactoryObjectFactory] Factory name: persistence.unit:unitName=#PRODUCT-PU
09:25:00,080 INFO [NamingHelper] JNDI InitialContext properties:{java.naming.factory.initial=org.jnp.interfaces.NamingContextFactory, java.naming.factory.url.pkgs=org.jboss.naming:org.jnp.interfaces}
09:25:00,088 INFO [SessionFactoryObjectFactory] Bound factory to JNDI name: persistence.unit:unitName=#PRODUCT-PU
09:25:00,088 WARN [SessionFactoryObjectFactory] InitialContext did not implement EventContext
09:25:00,088 INFO [NamingHelper] JNDI InitialContext properties:{java.naming.factory.initial=org.jnp.interfaces.NamingContextFactory, java.naming.factory.url.pkgs=org.jboss.naming:org.jnp.interfaces}
09:25:00,181 INFO [SessionSpecContainer] Starting jboss.j2ee:jar=Product-EJB.jar,name=ProductServiceImpl,service=EJB3
09:25:00,182 INFO [EJBContainer] STARTED EJB: com.lab.productsystem.ejb.session.ProductServiceImpl ejbName: ProductServiceImpl
09:25:00,211 INFO [JndiSessionRegistrarBase] Binding the following Entries in Global JNDI:


ProductServiceImpl/remote - EJB3.x Default Remote Business Interface
ProductServiceImpl/remote-com.lab.productsystem.ejb.session.ProductService - EJB3.x Remote Business Interface


[2011-05-18 09:25:00,251] Facet EJB: Facet is deployed successfully
09:25:02,621 INFO [TomcatDeployment] deploy, ctxPath=/Product-Web
09:25:02,771 INFO [[/Product-Web]] Initializing Spring FrameworkServlet 'springapp'
09:25:02,772 INFO [DispatcherServlet] FrameworkServlet 'springapp': initialization started
09:25:02,790 INFO [XmlWebApplicationContext] Refreshing org.springframework.web.context.support.XmlWebApplicationContext@148f1f: display name [WebApplicationContext for namespace 'springapp-servlet']; startup date [Wed May 18 09:25:02 SGT 2011]; root of context hierarchy
09:25:02,861 INFO [XmlBeanDefinitionReader] Loading XML bean definitions from ServletContext resource [/WEB-INF/springapp-servlet.xml]
09:25:02,994 INFO [XmlWebApplicationContext] Bean factory for application context [org.springframework.web.context.support.XmlWebApplicationContext@148f1f]: org.springframework.beans.factory.support.DefaultListableBeanFactory@aba36c
09:25:03,067 INFO [DefaultListableBeanFactory] Pre-instantiating singletons in org.springframework.beans.factory.support.DefaultListableBeanFactory@aba36c: defining beans [messageSource,pservice,productManager,viewResolver,urlHandler,productController,productControllerResolver]; root of factory hierarchy
09:25:03,225 INFO [DispatcherServlet] FrameworkServlet 'springapp': initialization completed in 453 ms
[2011-05-18 09:25:03,231] Facet Web: Facet is deployed successfully

 
Answer #3    Answered By: Blowice Yang     Answered On: May 18

I found the solution after inspired by jaikiran pai from jboss community forum. In case anyone need it.

the revised spring config file is this:


<jee:jndi-lookup id="pservice" jndi-name="ProductServiceImpl/remote" lookup-on-startup="false" proxy-interface="com.lab.productsystem.ejb.session.ProductService"></jee:jndi-lookup>

 
Didn't find what you were looking for? Find more on spring + ejb3 not bound strange issue Or get search suggestion and latest updates.




Tagged: