Im trying to established connection with JMS using Apache Camel, the server is using JNP protocal but always ends with an exceptions.
Need help here, am i missing or doing some thing wrong here.
Technology Stack.
JBoss Fuse 6.3
Apache Camel (for integration)
Blueprint:
<bean id="remoteJndiTemplate" class="org.springframework.jndi.JndiTemplate">
<property name="environment">
<props>
<prop key="java.naming.provider.url">jnp://X.X.X.X:1099</prop>
<prop key="java.naming.factory.url.pkgs">org.jnp.interfaces:org.jboss.naming</prop>
<prop key="java.naming.factory.initial">org.jnp.interfaces.NamingContextFactory</prop>
</props>
</property>
</bean>
<bean id="remoteConnectionFactory" class="org.springframework.jndi.JndiObjectFactoryBean" init-method="afterPropertiesSet">
<property name="jndiTemplate" ref="remoteJndiTemplate"/>
<property name="jndiName" value="ConnectionFactory" />
<property name="lookupOnStartup" value="false" />
<property name="proxyInterface" value="javax.jms.ConnectionFactory" />
</bean>
<bean id="jmsInConnectionFactory" factory-ref="remoteConnectionFactory" factory-method="getObject" />
<bean id="jmsComponent" class="org.apache.camel.component.jms.JmsComponent">
<property name="configuration">
<bean class="org.apache.camel.component.jms.JmsConfiguration">
<property name="connectionFactory" ref="jmsInConnectionFactory"/>
</bean>
</property>
</bean>
Exception:
org.osgi.service.blueprint.container.ComponentDefinitionException: Error setting property: PropertyDescriptor <name: expectedType, getter: class org.springframework.jndi.JndiObjectLocator.getExpectedType(), setter: [class org.springframework.jndi.JndiObjectLocator.setExpectedType(class java.lang.Class)]
at org.apache.aries.blueprint.container.BeanRecipe.setProperty(BeanRecipe.java:963)[23:org.apache.aries.blueprint.core:1.4.5]
Caused by: java.lang.Exception: Unable to convert
at org.apache.aries.blueprint.container.AggregateConverter.convertFromString(AggregateConverter.java:252)[23:org.apache.aries.blueprint.core:1.4.5]
Caused by: java.lang.ClassNotFoundException: javax.jms.QueueConnectionFactory not found by IDC-mnp-npg [294]
at org.apache.felix.framework.BundleWiringImpl.findClassOrResourceByDelegation(BundleWiringImpl.java:1556)[org.apache.felix.framework-4.4.1.jar:]
Looks like you're missing the JMS API jar on your classpath based on root caused-by of your exception:
Caused by: java.lang.ClassNotFoundException: javax.jms.QueueConnectionFactory not found by IDC-mnp-npg
Related
I am running a tasklet using Spring batch (4.1.4.RELEASE) and Spring jars (4.0.9.RELEASE) and getting the exception:
Caused by: java.lang.IllegalStateException: A transaction manager must be provided**
at org.springframework.util.Assert.state(Assert.java:385) ~[spring-core-4.0.9.RELEASE.jar:4.0.9.RELEASE]
at org.springframework.batch.core.step.tasklet.TaskletStep.afterPropertiesSet(TaskletStep.java:129) ~[spring-batch-core-4.1.4.RELEASE.jar:4.1.4.RELEASE]
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.invokeInitMethods(AbstractAutowireCapableBeanFactory.java:1613) ~[spring-beans-4.0.9.RELEASE.jar:4.0.9.RELEASE]
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1550) ~[spring-beans-4.0.9.RELEASE.jar:4.0.9.RELEASE]
... 41 more
Below I have shown the session factory XML-based configuration.
<bean id="sessionFactory"
class="org.springframework.orm.hibernate3.annotation.AnnotationSessionFactoryBean">
<property name="dataSource" ref="dataSource" />
<property name="configLocation" value="classpath:hibernate.cfg.xml" />
<property name="hibernateProperties">
<value>
hibernate.show_sql=false
hibernate.format_sql=false
hibernate.dialect=org.hibernate.dialect.Oracle10gDialect
hibernate.query.substitutions=true 'Y', false 'N'
hibernate.cache.use_second_level_cache=true
hibernate.cache.provider_class=net.sf.ehcache.hibernate.SingletonEhCacheProvider
hibernate.cache.use_query_cache=true
</value>
</property>
</bean>
<bean id="jdbcTransactionManager"
class="org.springframework.jdbc.datasource.DataSourceTransactionManager"
lazy-init="true">
<property name="dataSource" ref="dataSource" />
</bean>
<bean id="hibernatetransactionManager"
class="org.springframework.orm.hibernate3.HibernateTransactionManager"
lazy-init="true">
<property name="sessionFactory" ref="sessionFactory" />
</bean>
I have tried some changes in Spring batch and Spring core library versions but nothing is working and I am getting the same exception.
The error happens in org.springframework.batch.core.step.tasklet.TaskletStep.afterPropertiesSet(TaskletStep.java:129) ~[spring-batch-core-4.1.4.RELEASE.jar:4.1.4.RELEASE], which means you did not set a transaction manager on your tasklet.
You did not share your tasklet's configuration, but you need to make sure a transaction manager is set on it, this is a mandatory property.
I'm migrating an application from OC4J to WebLogic 12c and the Spring beans are giving an error I can't figure out how to solve. My question is what can be the cause of this error.
I have the following bean for the JNDI lookup:
<bean id="dataSource" class="org.springframework.jndi.JndiObjectFactoryBean">
<property name="jndiName" value="${datasource.jndiname}" />
<property name="lookupOnStartup">
<value>false</value>
</property>
<property name="proxyInterface">
<value>javax.sql.DataSource</value>
</property>
</bean>
The value ${datasource.jndiname} is expected to come from a config.properties file with the following line:
server.database.datasource=${datasource.jndiname}
And the value of server.database.datasource comes from a config.filter file with the line:
server.database.datasource=jdbc/DATASOURCE
This works fine with OC4J and it also works when I replace the ${datasource.jndiname} to its value jdbc/DATASOURCE in WebLogic, but it gives me the following error if I keep the reference (and I need to keep it):
JndiObjectTargetSource failed to obtain new target object; nested exception is javax.naming.NameNotFoundException: While trying to lookup '${datasource.jndiname}' didn't find subcontext '${datasource'. Resolved ''; remaining name '${datasource/jndiname}'
After some research, I found a property for the bean that fixed the error. Setting the property resourceRef to false makes the reference ${datasource.jndiname} work as expected.
In the final code shown below I also added a JndiTemplate.
<bean id="dsJndiTemplate" class="org.springframework.jndi.JndiTemplate">
<property name="environment">
<props>
<prop key="java.naming.provider.url">t3://localhost:7001</prop>
<prop key="java.naming.factory.initial">weblogic.jndi.WLInitialContextFactory</prop>
</props>
</property>
</bean>
<bean id="dataSource" class="org.springframework.jndi.JndiObjectFactoryBean">
<property name="jndiName" value="${datasource.jndiname}" />
<property name="resourceRef" value="false"/>
<property name="lookupOnStartup" value="false"/>
<property name="proxyInterface" value="javax.sql.DataSource"/>
<property name="jndiTemplate">
<ref local="dsJndiTemplate" />
</property>
</bean>
I have an application that uses Spring with Hibernate connecting to MS SQL Server.
The application connects fine without this property:
<prop key="hibernate.globally_quoted_identifiers">true</prop>
However, I need that property as some table names/columns have reserved names and I don't want to escape them all.
The configuration is:
<bean id="entityManagerFactory" class="org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean">
<property name="dataSource" ref="mainDataSource" />
<property name="packagesToScan" value="mypackage.entity" />
<property name="jpaVendorAdapter">
<bean class="org.springframework.orm.jpa.vendor.HibernateJpaVendorAdapter" />
</property>
<property name="jpaProperties">
<props>
<prop key="hibernate.dialect">${jdbc.dialect}</prop>
<prop key="hibernate.show_sql">${jdbc.showSql}</prop>
<prop key="hibernate.format_sql">${jdbc.showSql}</prop>
<prop key="hibernate.use_sql_comments">${jdbc.showSql}</prop>
<prop key="hibernate.globally_quoted_identifiers">true</prop>
</props>
</property>
</bean>
<!-- BoneCP configuration -->
<bean id="mainDataSource" class="com.jolbox.bonecp.BoneCPDataSource" destroy-method="close">
<property name="driverClass" value="${jdbc.driverClassName}" />
<property name="jdbcUrl" value="${jdbc.url}" />
<property name="username" value="${jdbc.username}"/>
<property name="password" value="${jdbc.password}"/>
<property name="idleConnectionTestPeriodInMinutes" value="60"/>
<property name="idleMaxAgeInMinutes" value="240"/>
<property name="maxConnectionsPerPartition" value="50"/>
<property name="minConnectionsPerPartition" value="5"/>
<property name="partitionCount" value="3"/>
<property name="acquireIncrement" value="5"/>
<property name="statementsCacheSize" value="100"/>
<property name="releaseHelperThreads" value="3"/>
</bean>
All of the properties are set. I'm using sqljdbc4.2. jdbc.driverClassName is set to com.microsoft.sqlserver.jdbc.SQLServerDriver. The JAR is in the WEB-INF/lib folder, the classpath, and the $CATALINA_HOME/lib folder. It works perfectly fine without the globally_quoted_identifiers property, but I can't figure out why adding it causes BoneCPDataSource to not be able to find the driver. Here is the error message:
Caused by: org.hibernate.MappingException: Unable to find column with logical name: my_entity_id in org.hibernate.mapping.Table(my_entity) and its related supertables and secondary tables
at org.hibernate.cfg.Ejb3JoinColumn.checkReferencedColumnsType(Ejb3JoinColumn.java:559)
at org.hibernate.cfg.BinderHelper.createSyntheticPropertyReference(BinderHelper.java:258)
at org.hibernate.cfg.ToOneFkSecondPass.doSecondPass(ToOneFkSecondPass.java:116)
at org.hibernate.cfg.Configuration.processEndOfQueue(Configuration.java:1596)
at org.hibernate.cfg.Configuration.processFkSecondPassInOrder(Configuration.java:1519)
at org.hibernate.cfg.Configuration.secondPassCompile(Configuration.java:1420)
at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1844)
at org.hibernate.jpa.boot.internal.EntityManagerFactoryBuilderImpl$4.perform(EntityManagerFactoryBuilderImpl.java:850)
... 33 more
[ERROR] 06/12/2016 10:44:15 [BoneCP-pool-watch-thread] [(ConnectionHandle:229)] Failed to acquire connection. Sleeping for 7000ms. Attempts left: 5
java.sql.SQLException: No suitable driver found for jdbc:sqlserver://localhost:1433;databaseName=SDC-Prod
at java.sql.DriverManager.getConnection(DriverManager.java:689)
at java.sql.DriverManager.getConnection(DriverManager.java:247)
at com.jolbox.bonecp.BoneCP.obtainRawInternalConnection(BoneCP.java:256)
at com.jolbox.bonecp.ConnectionHandle.obtainInternalConnection(ConnectionHandle.java:211)
at com.jolbox.bonecp.ConnectionHandle.<init>(ConnectionHandle.java:170)
at com.jolbox.bonecp.PoolWatchThread.fillConnections(PoolWatchThread.java:101)
at com.jolbox.bonecp.PoolWatchThread.run(PoolWatchThread.java:82)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
at java.lang.Thread.run(Thread.java:745)
[ERROR] 06/12/2016 10:44:15 [BoneCP-pool-watch-thread] [(CustomThreadFactory:89)] Uncaught Exception in thread BoneCP-pool-watch-thread
java.lang.NoClassDefFoundError: com/jolbox/bonecp/hooks/ConnectionState
at com.jolbox.bonecp.ConnectionHandle.markPossiblyBroken(ConnectionHandle.java:291)
at com.jolbox.bonecp.ConnectionHandle.obtainInternalConnection(ConnectionHandle.java:241)
at com.jolbox.bonecp.ConnectionHandle.<init>(ConnectionHandle.java:170)
at com.jolbox.bonecp.PoolWatchThread.fillConnections(PoolWatchThread.java:101)
at com.jolbox.bonecp.PoolWatchThread.run(PoolWatchThread.java:82)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
at java.lang.Thread.run(Thread.java:745)
Caused by: java.lang.ClassNotFoundException: com.jolbox.bonecp.hooks.ConnectionState
at org.apache.catalina.loader.WebappClassLoaderBase.loadClass(WebappClassLoaderBase.java:1892)
at org.apache.catalina.loader.WebappClassLoaderBase.loadClass(WebappClassLoaderBase.java:1735)
... 8 more
It seemed like the find table was failing because it couldn't connect, but just can't seem to find the link between the globally_quoted_identifiers and the driver class.
I have simple application with following folder structure:
ProjFolder
|-----src
|----------packagename
|---------------{sourcefiles}
|----------META-INF
|---------------{beans.xml}
|---------------{hibernate.cfg.xml}
|---------------{EntityMapping.hbm.xml}
here is the part of beans.xml Spring config file:
<bean id="propertyConfigurer" class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
<property name="location" value="classpath:./META-INF/jdbc.properties" />
</bean>
<bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource" destroy-method="close">
<property name="driverClassName" value="${jdbc.driverClassName}" />
<property name="url" value="${jdbc.url}" />
<property name="username" value="${jdbc.username}" />
<property name="password" value="${jdbc.password}" />
</bean>
<bean id="sessionFactory" class="org.springframework.orm.hibernate3.LocalSessionFactoryBean">
<property name="dataSource" ref="dataSource" />
<property name="configLocation" value="classpath:./META-INF/hibernate.cfg.xml" />
<property name="hibernateProperties">
<props>
<prop key="hibernate.dialect">${hibernate.dialect}</prop>
</props>
</property>
<property name="mappingResources">
<list>
<value>classpath:./META-INF/EntityMapping.hbm.xml</value>
</list>
</property>
</bean>
<tx:annotation-driven transaction-manager="txManager" />
<bean id="txManager" class="org.springframework.orm.hibernate3.HibernateTransactionManager">
<property name="sessionFactory" ref="sessionFactory" />
</bean>
when i start my unit tests i getting following exception:
org.springframework.beans.factory.BeanCreationException: Error
creating bean with name 'wrapperClass' defined in class path resource
[META-INF/beans.xml]: Cannot resolve reference to bean 'wrapperClassField'
while setting constructor argument; nested exception is
org.springframework.beans.factory.BeanCreationException: Error
creating bean with name 'xmlBooksource' defined in class path resource
[META-INF/beans.xml]: Cannot resolve reference to bean
'sessionFactory' while setting bean property 'sessionFactory'; nested
exception is org.springframework.beans.factory.BeanCreationException:
Error creating bean with name 'sessionFactory' defined in class path
resource [META-INF/beans.xml]: Invocation of init method failed;
nested exception is java.io.FileNotFoundException: class path resource
[classpath:/META-INF/EntityMapping.hbm.xml] cannot be opened because it does not exist
The same exception is thrown when i type
<property name="mappingResources">
<list>
<value>EntityMapping.hbm.xml</value>
</list>
</property>
Why spring cant find this file and how i must fill its location to make this code work?
Thanks in advance.
Have you tried removing the classpath: prefix? In looking at the Hibernate code, the mappingResources setter expects passes the strings to new ClassPathResource(String). This expects classpath resources already. The string then gets passed to ClassLoader.getResourceAsStream(String). None of this code would strip the "classpath:" prefix from the front of the resource string.
I'm not sure the error message is consistent with the beans.xml content you posted.
In the error you have
[classpath:/META-INF/EntityMapping.hbm.xml]
which isn't the same as
classpath:./META-INF/EntityMapping.hbm.xml
Notice the missing "." at the beginning in the error.
The second beans.xml configuration, should probably produce a different error message with:
[classpath:EntityMapping.hbm.xml]
This would be searching for the file in the root of your compiled application (jar, war, exploded, what have you).
I have successfully configure Hibernate 4 with Spring 3.1. My applicationContext.xml file is inside web-inf folder and has the following hibernate cofiguration:
<!-- Session Factory Declaration -->
<bean id="SessionFactory" class="org.springframework.orm.hibernate4.LocalSessionFactoryBean">
<property name="dataSource" ref="DataSource" />
<!--
<property name="annotatedClasses">
<list>
<value>iltaf.models.Levels</value>
</list>
</property>
-->
<property name="mappingLocations" value="classpath:iltaf/models/*.hbm.xml" />
<property name="configLocation">
<value>classpath:hibernate.cfg.xml</value>
</property>
<property name="hibernateProperties">
<props>
<prop key="hibernate.dialect">org.hibernate.dialect.MySQL5Dialect</prop>
<prop key="hibernate.show_sql">true</prop>
</props>
</property>
</bean>
<!-- Enable the configuration of transactional behavior based on annotations -->
<tx:annotation-driven transaction-manager="txManager"/>
<!-- Transaction Manager is defined -->
<bean id="txManager" class="org.springframework.orm.hibernate4.HibernateTransactionManager">
<property name="sessionFactory" ref="SessionFactory"/>
</bean>
</beans>
and I have separate hibernate.cfg.xml file inside my src folder. I am using Eclipse Juno Java EE version.
I use Spring-configured jms template with tibco jms library.
I get jms connection factory and topic with JNDI and these objects are not null. But when I try to send message or add listener I get this exception:
For listener:
Exception in thread "main" org.springframework.jms.InvalidDestinationException: Can not send into foreign destinations; nested exception is javax.jms.InvalidDestinationException: Can not send into foreign destinations
at org.springframework.jms.support.JmsUtils.convertJmsAccessException(JmsUtils.java:277)
at org.springframework.jms.support.JmsAccessor.convertJmsAccessException(JmsAccessor.java:168)
at org.springframework.jms.core.JmsTemplate.execute(JmsTemplate.java:474)
at org.springframework.jms.core.JmsTemplate.receiveSelected(JmsTemplate.java:700)
at org.springframework.jms.core.JmsTemplate.receive(JmsTemplate.java:682)
at org.springframework.jms.core.JmsTemplate.receive(JmsTemplate.java:674)
For sender:
Exception in thread "main" org.springframework.jms.InvalidDestinationException: Invalid or foreigndestination; nested exception is javax.jms.InvalidDestinationException: Invalid or foreigndestination
at org.springframework.jms.support.JmsUtils.convertJmsAccessException(JmsUtils.java:277)
at org.springframework.jms.support.JmsAccessor.convertJmsAccessException(JmsAccessor.java:168)
at org.springframework.jms.core.JmsTemplate.execute(JmsTemplate.java:474)
at org.springframework.jms.core.JmsTemplate.send(JmsTemplate.java:539)
at org.springframework.jms.core.JmsTemplate.send(JmsTemplate.java:531)
Client app is working with the same topic without problems (so jms server is running). Do you have any ideas? I read about this exception in javadoc, but can't find how to understand the root issue and fix it.
Thanks
UPD:
JMS-related part of config:
<bean id="JmsFactory" class="org.springframework.jndi.JndiObjectFactoryBean">
<property name="jndiName" value="${jms.factory}"/>
<property name="proxyInterface" value="javax.jms.TopicConnectionFactory" />
<property name="lookupOnStartup" value="false" />
<property name="jndiEnvironment">
<props>
<prop key="java.naming.provider.url">${jms.namingProvider}</prop>
<prop key="java.naming.factory.initial">${jms.namingFactory}</prop>
<prop key="java.naming.referral">${jms.namingReferral}</prop>
<prop key="java.naming.security.credentials">${jms.securityCredentials}</prop>
<prop key="java.naming.security.principal">${jms.securityPrincipal}</prop>
</props>
</property>
</bean>
<bean id="JmsTopic" class="org.springframework.jndi.JndiObjectFactoryBean">
<property name="jndiName" value="${jms.topic}"/>
<property name="proxyInterface" value="javax.jms.Topic" />
<property name="lookupOnStartup" value="false" />
<property name="jndiEnvironment">
<props>
<prop key="java.naming.provider.url">${jms.namingProvider}</prop>
<prop key="java.naming.factory.initial">${jms.namingFactory}</prop>
<prop key="java.naming.referral">${jms.namingReferral}</prop>
<prop key="java.naming.security.credentials">${jms.securityCredentials}</prop>
<prop key="java.naming.security.principal">${jms.securityPrincipal}</prop>
</props>
</property>
</bean>
<bean id="UserCredentialsConnectionFactory"
class="org.springframework.jms.connection.UserCredentialsConnectionFactoryAdapter">
<property name="targetConnectionFactory">
<ref bean="JmsFactory" />
</property>
<property name="username" value="${jms.user}" />
<property name="password" value="${jms.password}" />
</bean>
<bean id="JmsTemplate"
class="org.springframework.jms.core.JmsTemplate">
<property name="connectionFactory"
ref="UserCredentialsConnectionFactory" />
<property name="defaultDestination">
<ref bean="JmsTopic"/>
</property>
<property name="pubSubDomain" value="true" />
</bean>
It sounds like you have it configured so that it is attempting to create a destination rather than do a jndi lookup to get the destination that has been defined on the EMS instance.
You need to post your spring config to be sure though.
edit: if you set a destinationname on the JmsTemplate and provide it with a JndiDestinationResolver then it should work