I wanted to export a bean as a OSGi service , so that this can be used in another bundle. But I get the below error. Please help.
SEVERE: Unable to create application context for [com.abc.test.impl], unsatisfied dependencies: Dependency on [(objectClass=com.abc.platform.test.manager.ITestManager)] (from bean [&testManager])
org.springframework.context.ApplicationContextException: Application context initialization for 'com.xyz.test.impl' has timed out waiting for (objectClass=com.abc.test.manager.ITestManager)
The code is given below.
Bundle 1 (com.abc.test.impl) :
Bean declaration -
<bean id="testManagerTarget" class="com.abc.platform.test.TestManager">
<property name="sessionFactory" ref="sessionFactory"/>
</bean>
<bean id="testManager" class="org.springframework.transaction.interceptor.TransactionProxyFactoryBean">
<property name="transactionManager">
<ref bean="transactionManager" />
</property>
<property name="target">
<ref bean="testManagerTarget" />
</property>
<property name="transactionAttributes">
<props>
<prop key="store">PROPAGATION_REQUIRED</prop>
</props>
</property>
</bean>
Declaring bean as OSGI service -
Text content in the code blocks is automatically word-wrapped
<osgi:service id="testManagerService" ref="testManager" interface="com.abc.platform.test.manager.ITestManager" />
Bundle 2 (com.xyz.test.impl):
<osgi:reference id="testManager" interface="com.abc.platform.test.manager.ITestManager" />
Really appreciate any help.
Thanks
Soniya
Related
I recently changed some of my application to use the the following:
org.springframework.jndi.JndiTemplate
org.springframework.jms.connection.CachingConnectionFactory
org.springframework.jms.core.JmsTemplate
Everything is working fine and I'm able to deploy my war files and send JMS messages to the queue.
However something peculiar happens when my managed server restarts. The deployables will all go into a fail state which requires me to then manually start them up.
This started happening after the change to use caching connection factory, jndi template and jms template.
My SpringConfig file:
<!-- Service Controller begin -->
<bean id="appUtils" class="com.foo.util.AppUtil" lazy-init="true" />
<bean id="jms_jndiTemplate" class="org.springframework.jndi.JndiTemplate" lazy-init="true">
<property name="environment">
<props>
<prop key="java.naming.factory.initial">#{jmsJndiFactory}</prop>
<prop key="java.naming.provider.url">#{jmsIp}</prop>
</props>
</property>
</bean>
<bean id="jmsUtils" class="com.foo.JmsUtil" >
<property name="template">
<bean class="org.springframework.jms.core.JmsTemplate" lazy-init="true">
<property name="connectionFactory">
<bean class="org.springframework.jms.connection.CachingConnectionFactory" lazy-init="true">
<property name="sessionCacheSize" value="10" />
<property name="targetConnectionFactory">
<bean class="org.springframework.jndi.JndiObjectFactoryBean">
<property name="jndiTemplate" ref="jms_jndiTemplate" />
<property name="jndiName" ref="jmsFactory" />
</bean>
</property>
</bean>
</property>
</bean>
</property>
<property name="destination">
<bean class="org.springframework.jndi.JndiObjectFactoryBean" lazy-init="true">
<property name="jndiTemplate" ref="jms_jndiTemplate" />
<property name="jndiName" ref="jmsQueue" />
</bean>
</property>
</bean>
ApplicationContext file:
<bean id="jmsQueue" class="java.lang.String" ><constructor-arg value="${jmsQueue.local}" /></bean>
<bean id="jmsFactory" class="java.lang.String" ><constructor-arg value="${jmsFactory.local}" /></bean>
<bean id="jmsJndiFactory" class="java.lang.String" ><constructor-arg value="${jmsJndiFactory.local}" /></bean>
<bean id="jmsIp" class="java.lang.String" ><constructor-arg value="${jmsIp.local}" /></bean>
applicationProperties file:
jmsQueue.local=jms/Queue
jmsFactory.local=jms/ConnectionFactory
jmsJndiFactory.local=weblogic.jndi.WLInitialContextFactory
jmsIp.local=t3://localhost:7031
Anyone has any idea as to why this might be happening? I'm using Weblogic. Any help would be greatly appreciated.
Thanks!
Edit: Forgot to mention that the error causing the failed state is
javax.naming.NameNotFoundException: Unable to resolve 'jms.Queue'. Resolved 'jms'; remaining name 'Queue'.
This is a JNDI error. The message means "I tried to find jms/Queue in the JNDI context but I only got as far as jms; there is no Queue child below".
Check the resources which you configured for the application in WebSphere.
I could not found any decent, clear example to learn JMS component with Spring configuration. So I wrote something like this:
<bean id="weblogic" class="org.apache.camel.component.jms.JmsComponent">
<property name="connectionFactory" ref="jmsConnectionFactory"/>
</bean>
<bean id="jmsJndiTemplate" class="org.springframework.jndi.JndiTemplate">
<property name="environment">
<props>
<prop key="java.naming.factory.initial">weblogic.jndi.WLInitialContextFactory</prop>
<prop key="java.naming.provider.url">t3://${ip}:${port}</prop>
</props>
</property>
</bean>
<bean id="jmsConnectionFactory" class="org.springframework.jndi.JndiObjectFactoryBean">
<property name="jndiTemplate" ref="jmsJndiTemplate"/>
<property name="jndiName" value="jms/cdrPreMO-connfact-jndi"/>
</bean>
<camelContext id="camelContext" xmlns="http://camel.apache.org/schema/spring">
<camel:endpoint id="jmsQueue" uri="weblogic:queue:jms/cdrPreMO-queue-jndi"/>
<route>
<from ref="jmsQueue"/>
<bean ref="test" method="writeFile"/>
<to uri="log:errors?level=ERROR"/>
</route>
</camelContext>
But it gives the exception :
Caused by: javax.naming.NameNotFoundException: Unable to resolve 'weblogic.jms.backend.jms'. Resolved 'weblogic.jms.backend'; remaining name 'jms'
at weblogic.jndi.internal.BasicNamingNode.newNameNotFoundException(BasicNamingNode.java:1139)
at weblogic.jndi.internal.BasicNamingNode.lookupHere(BasicNamingNode.java:252)
at weblogic.jndi.internal.ServerNamingNode.lookupHere(ServerNamingNode.java:182)
at weblogic.jndi.internal.BasicNamingNode.lookup(BasicNamingNode.java:206)
at weblogic.jndi.internal.BasicNamingNode.lookup(BasicNamingNode.java:214)
at weblogic.jndi.internal.BasicNamingNode.lookup(BasicNamingNode.java:214)
at weblogic.jndi.internal.BasicNamingNode.lookup(BasicNamingNode.java:214)
at weblogic.jndi.internal.WLEventContextImpl.lookup(WLEventContextImpl.java:254)
at weblogic.jndi.internal.WLContextImpl.lookup(WLContextImpl.java:393)
at weblogic.jms.frontend.FEManager.destinationCreate(FEManager.java:287)
... 8 more
JMS Conf is true(ip port and jndi names). It is getting the connection, and the session but gives the exception
Could someone tell me what are my mistakes?
Thanx
EDIT: fix applied according to the comment of Claus.
The Camel endpoints should refer to "weblogic" as the component name.
<camel:endpoint id="jmsQueue" uri="jms:queue:jms/cdrPreMO-queue-jndi"/>
Should be
<camel:endpoint id="jmsQueue" uri="weblogic:queue:jms/cdrPreMO-queue-jndi"/>
As that is the name you gave the JMS component in the id attribute of the < bean > tag, eg
<bean id="weblogic" class="org.apache.camel.component.jms.JmsComponent">
<property name="connectionFactory" ref="jmsConnectionFactory"/>
</bean>
Solved but with a workaround. I still do not know what the problem really is but, instead of weblogic create its own destination by itself, I gave the responsibility to spring like:
<bean id="weblogic" class="org.apache.camel.component.jms.JmsComponent">
<property name="configuration" ref="jmsConfiguration" />
</bean>
<bean id="jmsJndiTemplate" class="org.springframework.jndi.JndiTemplate">
<property name="environment">
<props>
<prop key="java.naming.factory.initial">weblogic.jndi.WLInitialContextFactory</prop>
<prop key="java.naming.provider.url">${ip}:${port}</prop>
</props>
</property>
</bean>
<bean id="jndiDestinationResolver" class="org.springframework.jms.support.destination.JndiDestinationResolver">
<property name="jndiTemplate" ref="jmsJndiTemplate"/>
</bean>
<bean id="jmsConfiguration" class="org.apache.camel.component.jms.JmsConfiguration">
<property name="connectionFactory" ref="jmsConnectionFactory"/>
<property name="destinationResolver" ref="jndiDestinationResolver"/>
</bean>
<bean id="jmsConnectionFactory" class="org.springframework.jndi.JndiObjectFactoryBean">
<property name="jndiTemplate" ref="jmsJndiTemplate"/>
<property name="jndiName" value="jms/cdrPreMO-connfact-jndi"/>
</bean>
It is working now.
Although question is pretty old, posting this solution for other users if they get this error. I ran into the this issue on Camel 2.19 version while trying to look up weblogic queue in weblogic 12c version. The lookup that happens here is most likely not a typical JNDI lookup when resolving queue destination in Weblogic.
The end point uri should contain the queue details as follows :
jms_server_name/jms_module_name!queue_name
For example if queue name is TestRequestQueue, created under a module named sample_jms_module and the JMS server is named sample_jms_server in Weblogic, then the uri would need to be as follows :
<camel:endpoint id="jmsQueue" uri="weblogic:queue:sample_jms_server/sample_jms_module!TestRequestQueue"/>
In the prefix portion of the uri weblogic:queue:, the component name can be anything as long as it refers to the created component. It needn't necessarily be weblogic. For example, if the JmsComponent is named as test-jms, the uri will need to be declared with prefix as test-jms:queue: .
Name of the JMS server in weblogic can be obtained from Weblogic console by navigating to the below path :
Services -> Messaging -> JMS Servers
Name of the queue, not the JNDI name, can be obtained from Weblogic console by navigating to the queue and clicking on Monitoring tab. This tab shows the destination name of the queue in the name column.
I've just run apache camel jms component in weblogic 12c with next configuration. The key is the jndi name for the queue.
It must be ./module_name!queueName. './' means local jms server.
<jee:jndi-lookup id="connectionFactoryBean" jndi-name="dpxcomConnectionFactory"/>
<bean id="dpxcomJMSConnectionFactory"
class="org.springframework.jms.connection.CachingConnectionFactory">
<constructor-arg ref="connectionFactoryBean"/>
<property name="sessionCacheSize" value="50"/>
</bean>
Route definition:
from("jms:queue:./DPXCOM!"+config.getMainQueueName()+"?concurrentConsumers="+config.getConcurrentConsumers()
+"&maxConcurrentConsumers="+config.getConcurrentConsumers()+"&jmsMessageType=Text&testConnectionOnStartup=true&connectionFactory=dpxcomJMSConnectionFactory&consumerType=Simple")
.setHeader("jmsMessage").body()
.process(new VerifyJMSMessageProcessor())
.choice()
..
..
end();
I am working on Spring + Struts2 and Hibernate currently, My requirement is :
I have Master module which will make DB connection, shared by all other modules (deployed as Jar) in the system.
All Module specific .hbm and persistence classes will exists in Module itself
So for example My master module will have Hibernate connection file (through spring) will all .hbm mapping files, Below is the sample of Hibernate connection made through Spring.
<bean id="dataSourceErik" class="org.apache.commons.dbcp.BasicDataSource" destroy-method="close">
<property name="driverClassName" value="com.mysql.jdbc.Driver" />
<property name="testWhileIdle" value="true" />
<property name="minEvictableIdleTimeMillis" value="120000" />
<property name="timeBetweenEvictionRunsMillis" value="30000" />
</bean>
<bean id="sessionFactoryErik"
class="org.springframework.orm.hibernate4.LocalSessionFactoryBean">
<property name="dataSource" ref="dataSourceErik" />
<property name="hibernateProperties">
<value>
hibernate.dialect=org.hibernate.dialect.MySQLDialect
hibernate.generate_statistics=true
hibernate.show_sql=false
hibernate.jdbc.batch_size=10
hibernate.bytecode.use_reflection_optimizer=true
hibernate.cache.provider_class=org.hibernate.cache.EhCacheProvider hibernate.cache.region.factory_class=org.hibernate.cache.ehcache.EhCacheRegionFactory
hibernate.cache.use_second_level_cache=true
hibernate.cache.use_query_cache=true
net.sf.ehcache.configurationResourceName=configuration/ehcache.xml
</value>
</property>
<property name="mappingLocations">
<list>
<value>classpath:configuration/hibernate/Abc.hbm.xml</value>
<value>classpath:configuration/hibernate/Xyz.hbm.xml</value>
</list>
</property>
</bean>
<bean id="AbcActionDAO" class="au.com.master.persistance.dao.AbcDbSession">
<constructor-arg ref="sessionFactoryErik" />
</bean>
<bean id="XyzActionTypeDAO"class="au.com.master.persistance.dao.XyzDbSession">
<constructor-arg ref="sessionFactoryErik" />
</bean>
if i add below code in above xml i can access '''sessionFactory''' and can connect with the DB. as i am giving the path of deployed subModule jar file, see below code :
<property name="mappingJarLocations">
<list>
<value>WEB-INF/lib/subModule.jar</value>
</list>
</property>
All above .hbm and DAO/DbSession classes exists in Master module. Now i want to use this '''sessionFactoryErik''' in my Sub modules deployed as jar. so for that i created another xml file in Sub module which will take reference of above '''sessionFactoryErik''' and will have mappings of this module specific .hbm and DAO/DbSession. Refer below code:
<bean id="sessionFactoryMonitor" class="org.springframework.orm.hibernate4.LocalSessionFactoryBean">
<property name="sessionFactoryErik" ref="sessionFactoryErik" />
<property name="mappingLocations">
<list>
<value>classpath:configuration/hibernate/DDDType.hbm.xml</value>
</list>
</property>
</bean>
<bean id="testActionDAO" class="au.com.java.subModule.persistance.dao.DddActionDbSession">
<constructor-arg ref="sessionFactoryMonitor" />
</bean>
if i deployed the project and reboot the server i am getting below error.
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'sessionFactoryMonitor' defined in URL [jar:file:/home/developer/Project/.metadata/.plugins/org.eclipse.wst.server.core/tmp0/webapps/erik/WEB-INF/lib/erik-monitor-1.0-SNAPSHOT.jar!/configuration/spring-monitor-dao.xml]: Error setting property values; nested exception is org.springframework.beans.NotWritablePropertyException: Invalid property 'sessionFactoryErik' of bean class [org.springframework.orm.hibernate4.LocalSessionFactoryBean]: Bean property 'sessionFactoryErik' is not writable or has an invalid setter method.
Can anyone help me for this. How can i get the same session object in sub module as only Master module can make connection as it will not have any knowledge of its deployed (deployed as jar) module.
Thanks.
Tapan
the class org.springframework.orm.hibernate4.LocalSessionFactoryBean doesn't have a property called sessionFactoryErik. I am guessing that you are injecting your datasource to LocalSessionFactoryBean. if so Change this
<bean id="sessionFactoryMonitor" class="org.springframework.orm.hibernate4.LocalSessionFactoryBean">
<property name="sessionFactoryErik" ref="sessionFactoryErik" />
<property name="mappingLocations">
<list>
<value>classpath:configuration/hibernate/DDDType.hbm.xml</value>
</list>
</property>
</bean>
to this
<bean id="sessionFactoryMonitor" class="org.springframework.orm.hibernate4.LocalSessionFactoryBean">
<property name="dataSource" ref="sessionFactoryErik" />
<property name="mappingLocations">
<list>
<value>classpath:configuration/hibernate/DDDType.hbm.xml</value>
</list>
</property>
</bean>
sessionFactoryErik bean returns org.hibernate.internal.SessionFactoryImpl object,
so you should specify org.hibernate.internal.SessionFactoryImpl or its super class
(SessionFactory) type in au.com.master.persistance.dao.XyzDbSession constructor
reference.
I am trying to run a hello world for: Spring/Hibernate with HSQLDB and C3PO connection pool.
the same code works with mySQL (only with different dialect and driver)
I have run the database and I can connect to it with the swing GUI. But when I try to run my application, I am getting a start up error.
Here are the details:
1: the error -
INFO: Initializing Spring root WebApplicationContext
[ERROR] [pool-2-thread-1 05:20:08] (JDBCExceptionReporter.java:logExceptions:101) Connections could not be acquired from the underlying database!
[ERROR] [pool-2-thread-1 05:20:08] (ContextLoader.java:initWebApplicationContext:220) Context initialization failed
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'sessionFactory' defined in ServletContext resource [/WEB-INF/hibernate-context.xml]: Invocation of init method failed; nested exception is org.hibernate.HibernateException: 'hibernate.dialect' must be set when no Connection avalable
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1420)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:519)
...
...
2: hibernate-context.xml -
<tx:annotation-driven transaction-manager="transactionManager" />
<bean id="sessionFactory" class="org.springframework.orm.hibernate3.annotation.AnnotationSessionFactoryBean">
<property name="dataSource" ref="dataSource" />
<property name="packagesToScan" value="com.gleeb.sample.model" />
<property name="hibernateProperties">
<props>
<!-- <prop key="dialect">org.hibernate.dialect.MySQL5InnoDBDialect</prop> -->
<prop key="dialect">org.hibernate.dialect.HSQLDialect</prop>
<prop key="show_sql">false</prop>
<prop key="hbm2ddl.auto">create</prop>
</props>
</property>
</bean>
<bean id="dataSource" class="com.mchange.v2.c3p0.ComboPooledDataSource"
destroy-method="close" p:driverClass="org.hsqldb.jdbc.JDBCDriver"
p:jdbcUrl="jdbc:hsqldb:hsql://localhost/testdb" p:user="sa"
p:password="" p:acquireIncrement="5" p:idleConnectionTestPeriod="60"
p:maxPoolSize="100" p:maxStatements="50" p:minPoolSize="10" />
<!-- Declare a transaction manager -->
<bean id="transactionManager"
class="org.springframework.orm.hibernate3.HibernateTransactionManager"
p:sessionFactory-ref="sessionFactory" />
As far as I can tell, it is not possible to pass in the dialect as a value set on the hibernateProperties field of a Spring Session Factory, at least if you are also using the configLocation property on it.
My hibernate.cfg.xml:
<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE hibernate-configuration PUBLIC "-//Hibernate/Hibernate Configuration DTD 3.0//EN" "http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd">
<hibernate-configuration>
<session-factory>
<property name="hibernate.dialect">org.hibernate.dialect.DB2Dialect</property>
<property name="hibernate.search.autoregister_listeners">false</property>
[etc...]
My relevant session factory context config:
<bean id="sessionFactory" class="org.springframework.orm.hibernate4.LocalSessionFactoryBean">
<property name="configLocation">
<value>classpath:hibernate.cfg.xml</value>
</property>
<property name="dataSource" ref="dataSource"/>
<property name="hibernateProperties">
<props>
<!--<prop key="hibernate.dialect">org.hibernate.dialect.DB2Dialect</prop>-->
<prop key="hibernate.show_sql">true</prop>
<prop key="hibernate.format_sql">true</prop>
<prop key="hibernate.generate_statistics">false</prop>
<prop key="hibernate.default_schema">xxx</prop>
</props>
</property>
</bean>
If I uncomment the dialect prop in the context file, and comment it out from in the hibernate.cfg.xml file I encounter the same exception as the OP:
Caused by: org.hibernate.HibernateException: Connection cannot be null when 'hibernate.dialect' not set
However if I run with the above configuration (commented out in the context file, uncommented in the hibernate.cfg.xml), it works, and I see the formatted hibernate SQL, showing that the other hibernate properties are being set by the context file.
I have session factory properties with hibernate. prefix.
<property name="hibernateProperties">
<value>
hibernate.dialect=org.hibernate.dialect.HSQLDialect
hibernate.hbm2ddl.auto=update
hibernate.show_sql=false
hibernate.format_sql=false
</value>
</property>
I have a requirement to configure JBoss WorkManager in my application. Earlier the configuration was as follows:
<bean id="taskExecutor" class="org.springframework.scheduling.commonj.WorkManagerTaskExecutor">
<property name="workManagerName" value="wm/default" />
</bean>
The clas "WorkManagerTaskExecutor" is intended for WebSphere and WebLogc. But we are migrating our application from WebSphere to JBOss. So I have the following configuration.
web.xml
<resource-ref id="ResourceRef_1163654014164">
<description>WorkManager</description>
<res-ref-name>WorkManager</res-ref-name>
<res-type>org.jboss.resource.work.JBossWorkManager</res-type>
<res-auth>Container</res-auth>
<res-sharing-scope>Shareable</res-sharing-scope>
</resource-ref>
jboss-web.xml
<resource-ref id="ResourceRef_1163654014164">
<description>WorkManager</description>
<res-ref-name>WorkManager</res-ref-name>
<jndi-name>WorkManager</jndi-name>
<ignore-dependency/>
</resource-ref>
applicationContext.xml
<bean id="taskExecutor" class="org.springframework.jca.work.jboss.JBossWorkManagerTaskExecutor">
</bean>
Exception Log:
17:04:39,472 ERROR [LogInterceptor]
EJBException in method: public abstract com.test.ejb.timer.SLATimer com.test.ejb.timer.SLATimerHome.create() throws javax.ejb.CreateException,java.rmi.RemoteException, causedBy:
org.springframework.beans.factory.BeanCreationException
: Error creating bean with name 'taskExecutor' defined in class path resource [spring-messaging.xml]: Invocation of init method failed; nested exception is java.lang.IllegalStateException: Could not initialize JBossWorkManagerTaskExecutor because JBoss API is not available:
java.lang.reflect.InvocationTargetException
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean (AbstractAutowireCapableBeanFactory.java:1420)
Caused by: java.lang.IllegalStateException: Could not initialize JBossWorkManagerTaskExecutor because JBoss API is not available:
java.lang.reflect.InvocationTargetException
Please help to fix the above issue.
Thanks
I am answering my question myself which may be helpful for somebody.
Removed configuration in web.xml and jboss.web.xml for this JBoss Work Manager.
Have the following configuration in applicationContext.xml
<bean id="jbossResourceAdapter" class="org.jboss.resource.adapter.jms.JmsResourceAdapter"/>
<bean id="mbeanServer" class="org.jboss.mx.util.MBeanServerLocator" factory-method="locateJBoss"/>
<bean id="chanduWorkManager" factory-bean="mbeanServer" factory-method="getAttribute">
<constructor-arg>
<bean class="org.springframework.jmx.support.ObjectNameManager" factory-method="getInstance">
<constructor-arg value="jboss.jca:service=ChanduWorkManager" />
</bean>
</constructor-arg>
<constructor-arg value="Instance" />
</bean>
<bean id="taskExecutor" class="org.springframework.jca.work.WorkManagerTaskExecutor">
<property name="workManager" ref="chanduWorkManager"/>
</bean>
<bean id="jbossResourceAdapterFactory" class="org.springframework.jca.support.ResourceAdapterFactoryBean">
<property name="resourceAdapter" ref="jbossResourceAdapter"/>
<property name="workManager" ref="taskExecutor"/>
</bean>
<bean id="jbossActivationSpecFactory" class="org.springframework.jms.listener.endpoint.StandardJmsActivationSpecFactory">
<property name="activationSpecClass" value="org.jboss.resource.adapter.jms.inflow.JmsActivationSpec"/>
<property name="defaultProperties">
<props>
<prop key="sessionTransacted">false</prop>
<prop key="minSession">1</prop>
<prop key="maxSession">15</prop>
</props>
</property>
</bean>
Hope it will help somebody.
Thanks,
Chandrasekhar Aadhanapattu
Find this may be the right answer....
In my case also AS is JBoss...
Spring WorkManagerTaskExecutor cannot initialize in websphere