spring-simple-memcache - maven dependencies for ReadThroughSingleCache - spring

Has anyone used spring simple memcached? I have not been able to get the exact maven dependency and the repository where this is available.
The dependencies mentioned on the code.google page (http://code.google.com/p/simple-spring-memcached/) mention other dependencies but it does not include jar for Simple-spring-memcache itself.
Thanks for the help guys.

Try this one:
<dependency>
<groupId>com.google.code.simple-spring-memcached</groupId>
<artifactId>simple-spring-memcached</artifactId>
<version>2.0.0</version>
</dependency>

In case of SSM 2.0.0 you need also memcached client (xmemcached or spymemcached):
<dependency>
<groupId>com.google.code.simple-spring-memcached</groupId>
<artifactId>simple-spring-memcached</artifactId>
<version>2.0.0</version>
</dependency>
<dependency>
<groupId>com.googlecode.xmemcached</groupId>
<artifactId>xmemcached</artifactId>
<version>1.3.5</version>
</dependency>
and configure connection to local memcached server:
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:aop="http://www.springframework.org/schema/aop"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
http://www.springframework.org/schema/aop
http://www.springframework.org/schema/aop/spring-aop-3.0.xsd">
<import resource="simplesm-context.xml" />
<aop:aspectj-autoproxy />
<bean name="defaultMemcachedClient" class="com.google.code.ssm.CacheFactory">
<property name="cacheClientFactory">
<bean class="com.google.code.ssm.providers.xmemcached.MemcacheClientFactoryImpl" />
</property>
<property name="addressProvider">
<bean class="com.google.code.ssm.config.DefaultAddressProvider">
<property name="address" value="127.0.0.1:11211" />
</bean>
</property>
<property name="configuration">
<bean class="com.google.code.ssm.providers.CacheConfiguration">
<property name="consistentHashing" value="true" />
</bean>
</property>
</bean>
</beans>

Related

mbeanExporter Invocation of init method failed UnableToRegisterMBeanException… is javax.management.InstanceAlreadyExistsException

I am getting "mbeanExporter Invocation of init method failed UnableToRegisterMBeanException… InstanceAlreadyExistsException" while trying to start a very simple Spring Batch Admin application in Websphere 8. The entire application can be downloaded from https://examples.javacodegeeks.com/enterprise-java/spring/spring-batch-admin-tutorial/.
This is a very simple Spring Batch Admin project with only one very simple job. I can successfully debug the project in Eclipse and I can build the war, deploy it to Websphere Liberty Profile 8.5 successfuly. By success I mean I can open the Spring Batch Admin console and trigger the job properly.
The error below I am getting only when I move such war to Mainframe Websphere 8.5 ND. I don't think it is direct related to mainframe/unix. In fact, I am wondering if it is not a conflict between the libraries described below in my Pom.xml and Websphere. Any idea what to check will be extremely appreciatted. Recently, I have certain issue when using Hibernate/JPA and by simply downgrade a bit the version fix the error. It was a bit similar scenario: works in Websphere Liberty Profile but didn't work in Websphere 8.5 ND until I downgrade the hibernate version in my pom.xml. Well, this time there is no hibernate at all but I typed here what fixed sometime ago and maybe it can help someone to give me some idea what to check. I have a scratch idea that it is library conflict but I don't know what to check or investigate.
I saw few people getting similar error by using Spring Boot but that isn't my case at all. Specially in Getting exception while refreshing Spring ApplicationContext in Spring Boot application someone got exactly same error as me after added
#EnableIntegrationMBeanExport(registration = RegistrationPolicy.REPLACE_EXISTING)
Nevertheless, I don't have any anotation in such project and I am not using EnableIntegrationMBeanExport at least explicitly. Maybe it is been used behind the scene but I am not that expert on it so if someone can give me possibilities to check it will be an excellent north. Additionally, I am not using Spring MVC.
Error when startuping the application
Trace: 2016/09/09 22:49:17.049 02 t=9BDE88 c=UNK key=P8 tag= (13007004)
SourceId: com.ibm.ws.webcontainer.webapp.WebApp.logServletError
ExtendedMessage: BBOO0220E: SRVE0293E: ÝServlet Error¨-ÝBatch Servlet¨: org.springframework.beans.factory.BeanCreationException: E
rror creating bean with name 'mbeanExporter': Invocation of init method failed; nested exception is org.springframework.jmx.export.U
nableToRegisterMBeanException: Unable to register MBean Ýorg.springframework.integration.monitor.IntegrationMBeanExporter#4ed60bcf¨
with key 'integrationMBeanExporter'; nested exception is javax.management.InstanceAlreadyExistsException: spring.application:cell=dt
l85cel,name=integrationMBeanExporter,type=IntegrationMBeanExporter,node=wlemyAppa,process=WLEmyApp
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.j
ava:1553)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.jav
a:539)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:
475)
at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:304)
at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:228)
at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:300)
at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:195)
at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:70
3)
at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:7
60)
...
at com.sun.jmx.interceptor.DefaultMBeanServerInterceptor.invoke(DefaultMBeanSe
at com.sun.jmx.mbeanserver.JmxMBeanServer.invoke(JmxMBeanServer.java:814)
at com.ibm.ws390.management.connector.corba.CorbaConnectorImpl.invoke(CorbaCon
at com.ibm.ws390.management.connector.corba._CorbaConnectorImplBase._invoke(_C
at com.ibm.ws390.orb.CommonBridge.invoke(CommonBridge.java:1898)
at com.ibm.ws390.orb.CommonBridge.getAndProcessWork(CommonBridge.java:725)
at com.ibm.ws390.orb.CommonBridge.runApplicationThread(CommonBridge.java:614)
at com.ibm.ws390.management.connector.corba.CorbaConnectorImpl.invoke(CorbaCon
at com.ibm.ws390.management.connector.corba._CorbaConnectorImplBase._invoke(_C
at com.ibm.ws390.orb.CommonBridge.invoke(CommonBridge.java:1898)
at com.ibm.ws390.orb.CommonBridge.getAndProcessWork(CommonBridge.java:725)
at com.ibm.ws390.orb.CommonBridge.runApplicationThread(CommonBridge.java:614)
at com.ibm.ws.util.ThreadPool$ZOSWorker.run(ThreadPool.java:2116)
Caused by: org.springframework.jmx.export.UnableToRegisterMBeanException: Unable to register MBean Ýorg.springframework.integration.
monitor.IntegrationMBeanExporter#4ed60bcf¨ with key 'integrationMBeanExporter';nested exception is javax.management.InstanceAlready
ExistsException: spring.application:cell=mycel,name=integrationMBeanExporter,type=IntegrationMBeanExporter,node=wlemyAppa,process=
WLEmyApp
pom.xml
<spring.version>4.0.5.RELEASE</spring.version>
<spring.batch.version>3.0.4.RELEASE</spring.batch.version>
<spring.jdbc.version>4.0.5.RELEASE</spring.jdbc.version>
<hsql.version>1.8.0.7</hsql.version>
<commons.version>1.4</commons.version>
<spring.oxm.version>4.0.5.RELEASE</spring.oxm.version>
<spring.batch.admin>1.3.1.RELEASE</spring.batch.admin>
</properties>
<dependencies>
<dependency>
<groupId>org.springframework.batch</groupId>
<artifactId>spring-batch-core</artifactId>
<version>${spring.batch.version}</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-context-support</artifactId>
<version>${spring.version}</version>
</dependency>
<dependency>
<groupId>hsqldb</groupId>
<artifactId>hsqldb</artifactId>
<version>${hsql.version}</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-jdbc</artifactId>
<version>${spring.jdbc.version}</version>
</dependency>
<dependency>
<groupId>commons-dbcp</groupId>
<artifactId>commons-dbcp</artifactId>
<version>${commons.version}</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-oxm</artifactId>
<version>${spring.oxm.version}</version>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>3.8.1</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.springframework.batch</groupId>
<artifactId>spring-batch-admin-manager</artifactId>
<version>${spring.batch.admin}</version>
<exclusions>
<exclusion>
<groupId>org.springframework.batch</groupId>
<artifactId>spring-context-support</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>org.springframework.batch</groupId>
<artifactId>spring-batch-admin-resources</artifactId>
<version>${spring.batch.admin}</version>
<exclusions>
<exclusion>
<groupId>org.springframework.batch</groupId>
<artifactId>spring-context-support</artifactId>
</exclusion>
</exclusions>
</dependency>
</dependencies>
<build>
<finalName>SpringBatchAdmin</finalName>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>2.2</version>
<configuration>
<source>1.7</source>
<target>1.7</target>
</configuration>
</plugin>
</plugins>
</build>
</project>
Job-config.xml
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:batch="http://www.springframework.org/schema/batch" xmlns:util="http://www.springframework.org/schema/util"
xmlns:task="http://www.springframework.org/schema/task" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.springframework.org/schema/batch
http://www.springframework.org/schema/batch/spring-batch-3.0.xsd
http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-4.0.xsd
http://www.springframework.org/schema/util
http://www.springframework.org/schema/util/spring-util-4.0.xsd">
<bean
class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
<property name="locations">
<list>
<value>classpath:batch-default.properties
</value>
</list>
</property>
<property name="searchSystemEnvironment" value="true" />
<property name="systemPropertiesModeName" value="SYSTEM_PROPERTIES_MODE_OVERRIDE" />
<property name="ignoreUnresolvablePlaceholders" value="true" />
</bean>
<job id="myjob" xmlns="http://www.springframework.org/schema/batch"
restartable="true">
<step id="myStep" allow-start-if-complete="true">
<tasklet>
<chunk reader="cvsFileItemReader" writer="itemWriter"
commit-interval="1000" />
</tasklet>
</step>
</job>
<bean id="cvsFileItemReader" class="org.springframework.batch.item.file.FlatFileItemReader">
<!-- property name="resource" value="${INPUT_FILE_LOCATION}"></property-->
<property name="resource" value="file:/C:/temp/sampleData.csv"></property>
<property name="linesToSkip" value="1"></property>
<property name="lineMapper">
<bean class="org.springframework.batch.item.file.mapping.DefaultLineMapper">
<property name="lineTokenizer">
<bean
class="org.springframework.batch.item.file.transform.DelimitedLineTokenizer">
<!-- <property name="names" value="${INCOMING_COLUMN_MAPPING}"></property> -->
<property name="names" value="firstName,lastName,city,id"></property>
</bean>
</property>
<property name="fieldSetMapper">
<bean
class="org.springframework.batch.item.file.mapping.BeanWrapperFieldSetMapper">
<property name="prototypeBeanName" value="userModel"></property>
</bean>
</property>
</bean>
</property>
</bean>
<bean id="itemWriter"
class="org.springframework.batch.item.database.JdbcBatchItemWriter">
<property name="dataSource" ref="dataSource"></property>
<property name="sql" value="${INSERT_QUERY}">
</property>
<property name="itemSqlParameterSourceProvider">
<bean
class="org.springframework.batch.item.database.BeanPropertyItemSqlParameterSourceProvider" />
</property>
</bean>
<bean id="userModel" class="com.javacodegeeks.example.util.UserModel"
scope="prototype" />
</beans>
Contex-config.xml
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:jdbc="http://www.springframework.org/schema/jdbc"
xsi:schemaLocation="
http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-3.2.xsd
http://www.springframework.org/schema/jdbc
http://www.springframework.org/schema/jdbc/spring-jdbc.xsd">
<!-- using in-memory store for batch meta-data -->
<bean id="jobRepository"
class="org.springframework.batch.core.repository.support.JobRepositoryFactoryBean">
<property name="dataSource" ref="dataSource" />
<property name="transactionManager" ref="transactionManager" />
<property name="databaseType" value="hsql" />
</bean>
<bean id="transactionManager" class="org.springframework.jdbc.datasource.DataSourceTransactionManager">
<property name="dataSource" ref="dataSource"></property>
</bean>
<bean id="jobLauncher"
class="org.springframework.batch.core.launch.support.SimpleJobLauncher">
<property name="jobRepository" ref="jobRepository" />
</bean>
<bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource"
lazy-init="true" destroy-method="close">
<property name="driverClassName" value="org.hsqldb.jdbcDriver" />
<property name="url"
value="jdbc:hsqldb:file:src/main/resources/hsqldb/batchcore.db;shutdown=true;" />
<property name="username" value="sa" />
<property name="password" value="" />
</bean>
</beans>
**** Edited:
I am reading Deploying two Spring batch applications in same cluster in a single Weblogic Domain? which explain how to make two Spring Batch Admin run in Weblogic.
I can see that the person was facing exactly same issue. After that I created another Spring Batch Admin and deployed to my local Websphere Liberty Profile then I got exact same error I was picking up in mainframe.
Firstly it made happy because I thought I finally found the problem and solution.
I fixed in my local websphere by adding /META-INF/spring/batch/override/jmx-context.xml with:
<?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:int-jmx="http://www.springframework.org/schema/integration/jmx" xmlns:context="http://www.springframework.org/schema/context"
xsi:schemaLocation="http://www.springframework.org/schema/integration/jmx http://www.springframework.org/schema/integration/jmx/spring-integration-jmx.xsd
http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-4.0.xsd
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-4.0.xsd">
<int-jmx:mbean-export id="integrationMBeanExporter" default-domain="SpringBatchAdmin" server="mbeanServer" />
<context:mbean-export default-domain="SpringBatchAdmin" server="mbeanServer" />
</beans>
Well that was great news untill I tried same approach in Websphere 8.5 ND running in mainframe. Exactly same issue remains there. Please, I am desparetly looking for anything else I can at least try.
had the same problem.
I have virtual hosting on the same machine where spring integration was used. Once deployed the test system everything was Ok. After a while, I deployed the prod system and all went wrong.
I specified at Application.class the following:
#EnableIntegrationMBeanExport(defaultDomain = "${managed.domain}")
and in the application.properties file I defined managed.domain the name.
The solution I've found here:
Tutorial

spring migration from 3x to 4x to create hibernate session factory

I have a working project for spring XA transaction (http://www.javaworld.com/article/2077714/java-web-development/xa-transactions-using-spring.html). I modified the project downloaded and created pom.xml since i had to integrate it with my project. Initially i started with spring 3x. I got it working properly for spring 3x. Now i have to integrate it with hibernate, so in order to create hibernate session factory, i stated migrating it to spring 4x.
i have following entries in my config file for spring 3x
spring config file:
<?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:aop="http://www.springframework.org/schema/aop"
xmlns:tx="http://www.springframework.org/schema/tx"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-3.0.xsd
http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-3.0.xsd ">
<bean id="dsProps" class="java.util.Properties">
<constructor-arg>
<props>
<prop key="user">root</prop>
<prop key="password"></prop>
<prop key="DYNAMIC_CLASS">com.findonnet.service.transaction.jboss.jdbc.Mysql
</prop>
</props>
</constructor-arg>
</bean>
<bean id="dataSource1"
class="org.springframework.jdbc.datasource.DriverManagerDataSource">
<property name="driverClassName">
<value>com.arjuna.ats.jdbc.TransactionalDriver</value>
</property>
<property name="url" value="jdbc:arjuna:mysql://localhost:8888/mydb1" />
<property name="connectionProperties">
<ref bean="dsProps" />
</property>
</bean>
<bean id="dataSource2"
class="org.springframework.jdbc.datasource.DriverManagerDataSource">
<property name="driverClassName">
<value>com.arjuna.ats.jdbc.TransactionalDriver</value>
</property>
<property name="url" value="jdbc:arjuna:mysql://localhost:8888/mydb2" />
<property name="connectionProperties">
<ref bean="dsProps" />
</property>
</bean>
<!-- ===================================================== -->
<!-- ==== TRANSACTION MANAGER CONFIG ===================== -->
<!-- ===================================================== -->
<bean id="jbossTransactionManager"
class="com.arjuna.ats.internal.jta.transaction.arjunacore.TransactionManagerImple">
</bean>
<bean id="jbossUserTransaction"
class="com.arjuna.ats.internal.jta.transaction.arjunacore.UserTransactionImple" />
<!-- use the JtaTransactionManager, since we have multiple resources to
deal with -->
<bean id="transactionManager"
class="org.springframework.transaction.jta.JtaTransactionManager">
<property name="transactionManager">
<ref bean="jbossTransactionManager" />
</property>
<property name="userTransaction">
<ref bean="jbossUserTransaction" />
</property>
</bean>
<!-- Begin sequenceDAO bean. Handles persistence of seq num in the DB -->
<bean id="sequenceDAO" class="com.findonnet.persistence.MessageSequenceDAO">
<property name="dataSource">
<ref bean="dataSource1" />
</property>
</bean>
<!-- End sequenceDAO bean -->
<!-- Begin sequenceDAO2 bean. Handles persistence of seq num in the DB -->
<bean id="sequenceDAO2" class="com.findonnet.persistence.MessageSequenceDAO">
<property name="dataSource">
<ref bean="dataSource2" />
</property>
</bean>
<!-- End sequenceDAO2 bean -->
<bean id="eventHandlerTarget" class="com.findonnet.messaging.EventHandler">
</bean>
<!-- declarative transaction demarcation -->
<bean id="eventHandler"
class="org.springframework.transaction.interceptor.TransactionProxyFactoryBean">
<property name="transactionManager">
<ref bean="transactionManager" />
</property>
<property name="target">
<ref bean="eventHandlerTarget" />
</property>
<property name="transactionAttributes">
<props>
<prop key="handle*">PROPAGATION_REQUIRED,-RuntimeException</prop>
</props>
</property>
</bean>
</beans>
and the pom.xml is having following entry:
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-jms</artifactId>
<version>3.0.7.RELEASE</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-jdbc</artifactId>
<version>3.0.7.RELEASE</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-context</artifactId>
<version>3.0.7.RELEASE</version>
</dependency>
This works completely fine. Now if i want to migrate to spring4x, i make the following changes:
<?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:aop="http://www.springframework.org/schema/aop"
xmlns:tx="http://www.springframework.org/schema/tx"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-4.0.xsd
http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-4.0.xsd
http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-4.0.xsd ">
and update my pom.xml as follows:
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-context</artifactId>
<version>4.0.0.RELEASE</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-orm</artifactId>
<version>4.0.0.RELEASE</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-jms</artifactId>
<version>4.0.0.RELEASE</version>
</dependency>
When i make the above changes and run my program, i get the following error:
org.springframework.jdbc.CannotGetJdbcConnectionException: Could not get JDBC Connection; nested exception is java.sql.SQLException: javax.naming.NoInitialContextException: Need to specify class name in environment or system property, or as an applet parameter, or in an application resource file: java.naming.factory.initial
at org.springframework.jdbc.datasource.DataSourceUtils.getConnection(DataSourceUtils.java:80)
at org.springframework.jdbc.core.JdbcTemplate.execute(JdbcTemplate.java:628)
at org.springframework.jdbc.core.JdbcTemplate.update(JdbcTemplate.java:907)
at org.springframework.jdbc.core.JdbcTemplate.update(JdbcTemplate.java:968)
at org.springframework.jdbc.core.JdbcTemplate.update(JdbcTemplate.java:973)
at com.findonnet.persistence.MessageSequenceDAO.insertSequence(MessageSequenceDAO.java:22)
at com.findonnet.messaging.EventHandler.handleEvent(EventHandler.java:53)
at com.findonnet.messaging.EventHandler$$FastClassByCGLIB$$dd9a9fb0.invoke(<generated>)
at org.springframework.cglib.proxy.MethodProxy.invoke(MethodProxy.java:204)
at org.springframework.aop.framework.CglibAopProxy$CglibMethodInvocation.invokeJoinpoint(CglibAopProxy.java:713)
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:157)
at org.springframework.transaction.interceptor.TransactionInterceptor$1.proceedWithInvocation(TransactionInterceptor.java:98)
at org.springframework.transaction.interceptor.TransactionAspectSupport.invokeWithinTransaction(TransactionAspectSupport.java:262)
at org.springframework.transaction.interceptor.TransactionInterceptor.invoke(TransactionInterceptor.java:95)
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:179)
at org.springframework.aop.framework.CglibAopProxy$DynamicAdvisedInterceptor.intercept(CglibAopProxy.java:646)
at com.findonnet.messaging.EventHandler$$EnhancerByCGLIB$$14d5f3ff.handleEvent(<generated>)
at com.findonnet.messaging.MainApp.main(MainApp.java:92)
Is there any other changes i have to make to get this project working with spring 4x.
I am trying to migrate to spring 4x since i have to make session factory as follows:
<bean id="sessionFactoryPayment"
class="org.springframework.orm.hibernate4.LocalSessionFactoryBean">
<property name="dataSource" ref="dataSourcePayment" />
<property name="configLocation">
<value>classpath:payment.hibernate.cfg.xml</value>
</property>
</bean>
You are mixing Spring4 and Hibernate4. You do not need to change anything to your configuration to migrate your application to Spring 4. Your latest code snippet would be valid if you were trying to migrate your application to Hibernate4.
You can also omit the version altogher in your XML configuration as there is a mapping in the spring's jar that ensure that the latest available version is always used.
This is what i did to solve the problem: I have my original program working for 3.0.7.RELEASE. I was trying to migrate to spring4 since i wanted to make use of org.springframework.orm.hibernate4.LocalSessionFactoryBean. Migrating to spring4 causing above exception by making use of 4.0.0.RELEASE.
Hibernate 4 support was added to Spring Framework in 3.1. So i replaced 3.0.7.RELEASE with 3.1.0.RELEASE and the problem (exception) is gone.

Spring jpa(Hibernate) with tomcat

I'm working with JPA(Hibernate) and spring project these days, I configured spring, jpa and try to deploy the application on tomcat7, As I know jpa/hibernate creates tables using entity class first loading, but here I couldn't see any connection between database and application when applications starts, below you can see my configuration,I have seen lot of questions posted regarding this matter, I couldn't find the proper solution to my problem.
Can any one tell me what is the problem here.I have created a application without any issues in jetty server sometime back,
Thank you in advance
applicationContext-dao.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:context="http://www.springframework.org/schema/context"
xmlns:tx="http://www.springframework.org/schema/tx"
xmlns:p="http://www.springframework.org/schema/p"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context-3.0.xsd
http://www.springframework.org/schema/tx
http://www.springframework.org/schema/tx/spring-tx-3.0.xsd"
default-lazy-init="true">
<!-- Use #Transaction annotations for managing transactions -->
<!--<tx:annotation-driven/>-->
<!-- holding properties for database connectivity / -->
<context:property-placeholder location="classpath:jdbc.properties"/>
<tx:annotation-driven proxy-target-class="true" />
<!-- Activates scanning of #Autowired -->
<context:annotation-config/>
<!-- Activates scanning of #Repository -->
<context:component-scan base-package="lk.gov.elg"/>
<bean class="org.springframework.orm.jpa.support.PersistenceAnnotationBeanPostProcessor" />
<tx:annotation-driven transaction-manager="transactionManager" />
<bean id="dataSource"
class="org.springframework.jdbc.datasource.DriverManagerDataSource"
p:driverClassName="${jdbc.driverClassName}"
p:url="${jdbc.url}"
p:username="${jdbc.username}"
p:password="${jdbc.password}"/>
<bean id="transactionManager" class="org.springframework.orm.jpa.JpaTransactionManager"
p:entityManagerFactory-ref="entityManagerFactory"
p:dataSource-ref="dataSource"/>
<bean class="org.springframework.jdbc.datasource.DataSourceTransactionManager">
<property name="dataSource" ref="dataSource"/>
</bean>
<bean id="entityManagerFactory"
class="org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean"
p:dataSource-ref="dataSource"
p:jpaVendorAdapter-ref="jpaAdapter">
<property name="persistenceUnitName" value="eLGPersistenceUnit"></property>
<property name="loadTimeWeaver">
<bean class="org.springframework.instrument.classloading.SimpleLoadTimeWeaver"/>
</property>
</bean>
<!-- Jpa adapter for the Hibernate -->
<bean id="jpaAdapter"
class="org.springframework.orm.jpa.vendor.HibernateJpaVendorAdapter"
p:databasePlatform="org.hibernate.dialect.MySQLDialect"
p:generateDdl="true"
p:showSql="true" >
</bean>
<bean
class="org.springframework.context.annotation.CommonAnnotationBeanPostProcessor"/>
<bean
class="org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor"/>
</beans>
persistance.xml
<?xml version="1.0" encoding="UTF-8"?>
<persistence version="2.0"
xmlns="http://java.sun.com/xml/ns/persistence" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/persistence http://java.sun.com/xml/ns/persistence/persistence_2_0.xsd">
<persistence-unit name="eLGPersistenceUnit"
transaction-type="RESOURCE_LOCAL">
<!--transaction-type="JTA">-->
<provider>org.hibernate.ejb.HibernatePersistence</provider>
<properties>
<property name="hibernate.hbm2ddl.auto" value="validate"/>
</properties>
<!--<provider>org.hibernate.ejb.HibernatePersistence</provider>-->
</persistence-unit>
</persistence>
I think there is no issue with your configuration, try after removing "default-lazy-init=true" attribute
Cheers
try changing:
<property name="hibernate.hbm2ddl.auto" value="validate"/>
to:
<property name="hibernate.hbm2ddl.auto" value="update"/>
or:
<property name="hibernate.hbm2ddl.auto" value="create"/>

java.lang.ClassNotFoundException: org.hibernate.cache.CacheProvider exception while integrating spring and hiberate

I am getting the below exception when I am trying to test the spring and hibernate integration.
Caused by: java.lang.ClassNotFoundException: org.hibernate.cache.CacheProvider
at java.net.URLClassLoader$1.run(URLClassLoader.java:366)
at java.net.URLClassLoader$1.run(URLClassLoader.java:355)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:354)
at java.lang.ClassLoader.loadClass(ClassLoader.java:423)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:308)
at java.lang.ClassLoader.loadClass(ClassLoader.java:356)
... 18 more
application-context
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:context="http://www.springframework.org/schema/context"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="
http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context-3.0.xsd">
<context:annotation-config/>
<!-- Datasource beans -->
<bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource">
<property name="url" value="jdbc:mysql://localhost:3306/sterlingschema" />
<property name="driverClassName" value="com.mysql.jdbc.Driver" />
<property name="username" value="root" />
<property name="password" value="root" />
</bean>
<!-- Hibernate Template session factory bean -->
<bean id="sessionFactory" class="org.springframework.orm.hibernate4.LocalSessionFactoryBean">
<property name="dataSource" ref="dataSource" />
<property name="hibernateProperties">
<props>
<prop key="hibernate.dialect">org.hibernate.dialect.MySQLDialect</prop>
<prop key="show_sql">true</prop>
<prop key="hibernate.hbm2ddl.auto">update</prop>
</props>
</property>
<property name="mappingResources">
<list>
<value>/org/droidaceapps/domain/users.hbm.xml</value>
</list>
</property>
</bean>
<!-- Hibernate template beans -->
<bean id="hibernateTemplate" class="org.springframework.orm.hibernate4.HibernateTransactionManager">
<property name="sessionFactory" ref="sessionFactory"></property>
</bean>
<!-- DAO beans -->
<bean id="userDAO" class="org.droidaceapps.dao.UserDAOImpl">
<property name="hibernateTemplate" ref="hibernateTemplate" />
</bean>
<!-- Service beans -->
<bean id="userService" class="org.droidaceapps.services.UserServiceImpl">
<property name="userDAO" ref="userDAO" />
</bean>
When I googled on this problem some said that we should be using springframework.orm.hibernate4 instead of springframework.orm.hibernate3. I did that. But still I am getting the same exception.
Can someone help me in Identifying what am I missing here.
Thanks
Note : org.hibernate.cache.Provider was removed in the change from Hibernate 3 to Hibernate 4.
If you use hibernate 3, you may get the java.lang.ClassNotFoundException: org.hibernate.cache.CacheProvider.
If you change to hibernate 4, you will not get that, but you firstly should add hibernate4.jar and spring-orm.jar.
It sounds liken you are missing hibernate dependency in your project set up:
Caused by: java.lang.ClassNotFoundException: org.hibernate.cache.CacheProvider
Try downloading hibernate-core.jar and add to your project classpath.
If you use Maven, simply add the following dependency to your project's pom.xml:
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-core</artifactId>
<version>${hibernate.version}</version>
</dependency>
Hope that helps.
You are injecting HibernateTransactionManager into DAO class instead of HibernateTemplate. Please check your configuration your file.
This solution worked for me too:
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-entitymanager</artifactId>
<version>3.6.10.Final</version>
</dependency>
In my case, I already had the hibernate-entitymanager dependency, but was attempting to use the latest version of hibernate - 4.3.1.Final. Not sure why the downgrade was necessary here, but chances are the "Simple Spring JPA Utility Project" I was basing off in STS 3.5.0.M2 of is also a little dated?
You have to change in spring configuration file.
change :
HibernateTemplate class as "org.springframework.orm.hibernate3.HibernateTemplate"
,and change:
LocalSessionFactoryBean bean as "org.springframework.orm.hibernate3.LocalSessionFactoryBean"
it will work.
This might be because you are using "org.springframework.orm.hibernate3.LocalSessionFactoryBean" instead of "org.springframework.orm.hibernate4.LocalSessionFactoryBean" for "sessionFactory" in spring configuration file.
If you're using Maven, try putting this in your POM file:
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-entitymanager</artifactId>
<version>3.6.10.Final</version>
</dependency>
That worked for me.

Spring security error with AOP

I want to delegate the security of my project in Spring Security, but when I add the dependencies to my POM and start the server I get an error that doesn't make sense... it says that my applicationContext.xml has an error and it points to the line where I have an aop sentence...
Here is a reduced version of my applicationContext.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:util="http://www.springframework.org/schema/util"
xmlns:context="http://www.springframework.org/schema/context"
xmlns:aop="http://www.springframework.org/schema/aop" xmlns:tx="http://www.springframework.org/schema/tx"
xsi:schemaLocation="
http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.1.xsd
http://www.springframework.org/schema/util http://www.springframework.org/schema/util/spring-util-3.1.xsd
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.1.xsd
http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-3.1.xsd
http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-3.1.xsd">
<!-- Activates scanning of #Autowired -->
<context:annotation-config/>
<!-- Activates scanning of #Repository and #Service -->
<context:component-scan base-package="es.myproject"/>
<!-- datasource configuration -->
<context:property-placeholder location="classpath:jdbc.properties" />
<bean id="dataSource" class="org.springframework.jndi.JndiObjectFactoryBean">
<property name="jndiName" value="${jndi.name}" />
<property name="lookupOnStartup" value="true"></property>
<property name="cache" value="true"></property>
<property name="proxyInterface" value="javax.sql.DataSource"></property>
</bean>
<!-- hibernate session factory -->
<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="packagesToScan" value="es.myproject.modelo.datos" />
</bean>
<!-- enable the configuration of transactional behavior based on annotations -->
<aop:aspectj-autoproxy />
<tx:annotation-driven transaction-manager="transactionManager" />
<!-- Transaction manager for a single Hibernate SessionFactory (alternative to JTA) -->
<bean id="transactionManager" class="org.springframework.orm.hibernate3.HibernateTransactionManager">
<property name="sessionFactory" ref="sessionFactory" />
</bean>
</beans>
These are de dependencies:
<!-- Spring security -->
<dependency>
<groupId>org.springframework.security</groupId>
<artifactId>spring-security-core</artifactId>
<version>3.1.0.RELEASE</version>
</dependency>
<dependency>
<groupId>org.springframework.security</groupId>
<artifactId>spring-security-web</artifactId>
<version>3.1.0.RELEASE</version>
</dependency>
<dependency>
<groupId>org.springframework.security</groupId>
<artifactId>spring-security-config</artifactId>
<version>3.1.0.RELEASE</version>
</dependency>
And the error points to <aop:aspectj-autoproxy /> in the applicationContext.xml
If I delete the Spring Security dependencies, the error goes away... weird huh? Any ideas anybody?
The error says:
org.xml.sax.SAXParseException: schema_reference.4: Failed to read schema document 'http://www.springframework.org/schema/aop/spring-aop-3.1.xsd', because 1) could not find the document; 2) the document could not be read; 3) the root element of the document is not <xsd:schema>.
org.springframework.beans.factory.xml.XmlBeanDefinitionStoreException: Line 41 in XML document from ServletContext resource [/WEB-INF/classes/applicationContext.xml] is invalid; nested exception is org.xml.sax.SAXParseException: cvc-complex-type.2.4.c: The matching wildcard is strict, but no declaration can be found for element 'aop:aspectj-autoproxy'.
But there's no real problem with reading that xsd, as I said if I delete the spring security dependencies this error doesn't show...
Strange. Your XML is valid (according to the W3 validator), and your bean definitions all look reasonable. That makes me think this is a classpath issue. Make sure that you have the following jars in your classpath:
aopalliance-1.0.jar
commons-logging-1.0.1.jar
spring-aop-3.1.0.RELEASE.jar
spring-asm-3.1.0.RELEASE.jar
spring-beans-3.1.0.RELEASE.jar
spring-context-3.1.0.RELEASE.jar
spring-core-3.1.0.RELEASE.jar
spring-expression-3.1.0.RELEASE.jar
spring-jdbc-3.1.0.RELEASE.jar
spring-orm-3.1.0.RELEASE.jar
spring-security-core-3.1.0.RELEASE.jar
spring-security-web-3.1.0.RELEASE.jar
spring-tx-3.1.0.RELEASE.jar
spring-web-3.1.0.RELEASE.jar
Also make sure that none of these appears multiple times (possibly with a different version)
Ah, re-reading your question, the problem may be that you don't explicitly list Spring 3.1.x as dependency. Spring Security 3.1.x only pulls Spring core 3.0.7 unless you explicitly request otherwise.
Add these dependencies and you should be safe:
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-aop</artifactId>
<version>3.1.0.RELEASE</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-orm</artifactId>
<version>3.1.0.RELEASE</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-context</artifactId>
<version>3.1.0.RELEASE</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-web</artifactId>
<version>3.1.0.RELEASE</version>
</dependency>

Resources