Spring Data Gemfire configuration issues - spring-data-gemfire

I am following the Spring Data Gemfire sample configuration on my application as below:
<gfe:cache/>
<gfe:local-region id="Customer">
<gfe:cache-listener>
<bean class="com.my.app.util.LoggingCacheListener"/>
</gfe:cache-listener>
</gfe:local-region>
<bean id="cacheManager" class="org.springframework.data.gemfire.support.GemfireCacheManager">
<property name="regions">
<set>
<ref bean="Customer"/>
</set>
</property>
</bean>
And got the issue as :
aused by: java.lang.NoSuchMethodError: org.springframework.util.StringUtils.isEmpty(Ljava/lang/Object;)Z
at org.springframework.data.gemfire.config.CacheParser.parsePdxDiskStore(CacheParser.java:113)
at org.springframework.data.gemfire.config.CacheParser.doParse(CacheParser.java:60)
at org.springframework.beans.factory.xml.AbstractSingleBeanDefinitionParser.parseInternal(AbstractSingleBeanDefinitionParser.java:85)
at org.springframework.beans.factory.xml.AbstractBeanDefinitionParser.parse(AbstractBeanDefinitionParser.java:59)
at org.springframework.beans.factory.xml.NamespaceHandlerSupport.parse(NamespaceHandlerSupport.java:73)
at org.springframework.data.gemfire.config.GemfireNamespaceHandler.parse(GemfireNamespaceHandler.java:46)
at org.springframework.beans.factory.xml.BeanDefinitionParserDelegate.parseCustomElement(BeanDefinitionParserDelegate.java:1423)
at org.springframework.beans.factory.xml.BeanDefinitionParserDelegate.parseCustomElement(BeanDefinitionParserDelegate.java:1413)
at org.springframework.beans.factory.xml.DefaultBeanDefinitionDocumentReader.parseBeanDefinitions(DefaultBeanDefinitionDocumentReader.java:184)
at org.springframework.beans.factory.xml.DefaultBeanDefinitionDocumentReader.doRegisterBeanDefinitions(DefaultBeanDefinitionDocumentReader.java:140)
at org.springframework.beans.factory.xml.DefaultBeanDefinitionDocumentReader.registerBeanDefinitions(DefaultBeanDefinitionDocumentReader.java:111)
at org.springframework.beans.factory.xml.XmlBeanDefinitionReader.registerBeanDefinitions(XmlBeanDefinitionReader.java:493)
at org.springframework.beans.factory.xml.XmlBeanDefinitionReader.doLoadBeanDefinitions(XmlBeanDefinitionReader.java:390)

The most likely the reason for this Exception is you are using an incompatible version of the core Spring Framework (e.g. earlier than 3.2.1) with Spring Data GemFire.
What version of Spring Data GemFire and the core Spring Framework are you using?
Spring Data GemFire as of 1.3.0 was already using the core Spring Framework 3.2.2.RELEASE.
If you are using the core Spring Framework 3.2.x line in your application, then I encourage you to use the latest, most stable version of the 3.2.x line, 3.2.9.RELEASE.
Spring Data GemFire 1.3.3 and later definitely requires core Spring Framework 3.2.1 or above.
Hope this helps!

Related

which spring-data-mongodb version is supported by Spring-boot 2.3.4 because I am getting this error while server startup locally

Failed to introspect Class [org.springframework.data.mongodb.config.MongoConfigurationSupport] from ClassLoader
java.lang.NoClassDefFoundError: org/springframework/data/support/IsNewStrategyFactory
Caused by: java.lang.ClassNotFoundException: org.springframework.data.support.IsNewStrategyFactory
Dependency versions are listed in an appendix of Spring Boot's reference documentation. In that appendix can see that Spring Boot 2.3.4.RELEASE uses 3.0.4.RELEASE of org.springframework.data:spring-data-mongodb by default.
If you use Spring Boot's dependency management, either by inheriting from spring-boot-starter-parent or importing spring-boot-dependencies, you can declare a dependency without a version and Spring Boot's dependency management will give you the correct version automatically. You can learn more about this in the reference documentation.

#SpringBootTest interferes with EclipseLink dynamic weaving

My company is developing a web application using Spring Boot, Spring MVC, JPA with EclipseLink and dynamic weaving.
My task is to prepare implementation of UI and integration tests spinning up the application using JUnit and #SpringBootTest and interacting with it using Selenium.
As stated at Spring Boot Testing Features,
Tests using the #SpringBootApplication annotation can make use of the #MockBean annotation to define Mockito mocks for beans within the ApplicationContext.
This is achieved by registering a BeanFactoryPostProcessor, MockitoPostProcessor, recursively scanning classes annotated with #Component or #Configuration for classes and fields annotated with #MockBean.
Unfortunately, this causes the entity classes referenced in those classes to be loaded before the LocalContainerEntityManagerFactoryBean that is supposed to scan for them is instantiated and set up with a LoadTimeWeaver, thus causing the load time weaving for those entities to be skipped.
This leads to NoSuchMethodExceptions for methods created by weaving like _persistence_propertyChange() when persistence actions are performed.
Is it possible to use #SpringBootTest with EclipseLink and dynamic weaving?
If not, what would be a good alternative to set up an integration test
for a recent Spring Boot version?
I solved the problem by using a custom SpringApplicationRunListener's contextPrepared() to remove the problematic BeanFactoryPostProcessors from the ApplicationContext before they got executed by Spring.
We encountered the same problem in a web app built with Spring Boot 2.1.6 and EclipseLink 2.7.6.
Is it possible to use #SpringBootTest with EclipseLink and dynamic weaving? If not, what would be a good alternative to set up an integration test for a recent Spring Boot version?
The solution was to set eclipselink.weaving JPA property to false in #SpringBootTest, and to true in regular operation.
Persistence config:
<bean id="entityManagerFactory" class="org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean">
<property name="jpaProperties">
<props>
<prop key="eclipselink.weaving">${jpa.eclipselink.weaving}</prop>
</props>
</property>
<!-- ... -->
</bean>
Then in application.properties:
jpa.eclipselink.weaving=true
And on JUnit test class:
#TestPropertySource(properties = "jpa.eclipselink.weaving=false")

Simplest working example of Spring Data JPA

I am searching for the simplest working example of spring controlled JPA(insert,update, delete).
I already found and tried many, still they not simple enough:
- http://spring.io/guides/gs/accessing-data-jpa/
- http://www.petrikainulainen.net/tutorials/
Prefereble easy to import so I could check it easly.
They find ok. Still persistance is not simplified enough.
I think insert and update of database data is simplified in http://www.mkyong.com/spring/spring-aop-transaction-management-in-hibernate/
From that change into delete is easy enough to me.
Then we can change Hibernate.xml to simpler mapping:
<bean id="sessionFactory"
class="org.springframework.orm.hibernate3.annotation.AnnotationSessionFactoryBean">
<property name="annotatedClasses">
<list>
<value>com.mkyong.product.model.Product</value>
</list>
</property>
http://www.java2s.com/Tutorials/Java/JPA/0020__JPA_Env_Setup.htm
Then add table Person to database(id (int autoincrement), name, surname), change url, change dialect in hibernate.dialect (ex. org.hibernate.dialect.MySQLDialect) and it works.
Then to make it work with Spring Data config as below
package com.java2s.common;
import org.springframework.data.jpa.repository.config.EnableJpaRepositories;
#EnableJpaRepositories
class Config {}
Or configure in xml context(src/main/resources/applicationContext.xml) add //schema releated entry, xmlns:jpa and <jpa:repositories base-package="com.java2s.common"/>
Place App.java in package other than com.java2s.common.
In pom.xml if U want latest version:
<dependency>
<groupId>org.springframework.data</groupId>
<artifactId>spring-data-jpa</artifactId>
<version>1.7.1.RELEASE</version>
</dependency>
I and updated all spring dependencies to 4.0.2.RELEASE, for spring version 3 U will need spring-data-jpa in version 1.6.4.RELEASE.

NoSuchMethodError when compiling in Eclipse with Spring IDE

I have a development environment based on Eclipse Juno with Spring IDE installed. My project uses also Spring Security. The Spring version I am using is 2.5.5 and Spring Security is at 2.0.6. Now, after updating Spring IDE from 3.1.0 to 3.3.0, I am getting a NoSuchMethodError when Spring compiler is trying to compile this line:
<security:authentication-provider user-service-ref="userDetailsService" />
<bean id="userDetailsService" class="com.mycompany.security.MyUserDetailsService">
<property name="daoFactory" ref="DaoFactory" />
</bean>
MyUserDetailsService implements UserDetailsService and InitializingBean.
schemaLocation for the file has been defined as:
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-2.5.xsd
http://www.springframework.org/schema/security
http://www.springframework.org/schema/security/spring-security-2.0.6.xsd"
The stacktrace looks like this:
!MESSAGE Error occured processing '/Server/WEB-INF/business-layer-context.xml'
!STACK 0
java.lang.NoSuchMethodError: org.springframework.beans.factory.support.BeanDefinitionBuilder.addConstructorArg(Ljava/lang/Object;)Lorg/springframework/beans/factory/support/BeanDefinitionBuilder;
at org.springframework.security.config.AuthenticationProviderBeanDefinitionParser.parse(AuthenticationProviderBeanDefinitionParser.java:88)
at org.springframework.beans.factory.xml.NamespaceHandlerSupport.parse(NamespaceHandlerSupport.java:74)
at org.springframework.ide.eclipse.beans.core.internal.model.namespaces.DelegatingNamespaceHandlerResolver$ElementTrackingNamespaceHandler.parse(DelegatingNamespaceHandlerResolver.java:177)
at org.springframework.beans.factory.xml.BeanDefinitionParserDelegate.parseCustomElement(BeanDefinitionParserDelegate.java:1427)
at org.springframework.ide.eclipse.beans.core.internal.model.BeansConfig$ErrorSuppressingBeanDefinitionParserDelegate.parseCustomElement(BeansConfig.java:1400)
at org.springframework.beans.factory.xml.BeanDefinitionParserDelegate.parseCustomElement(BeanDefinitionParserDelegate.java:1417)
at org.springframework.beans.factory.xml.DefaultBeanDefinitionDocumentReader.parseBeanDefinitions(DefaultBeanDefinitionDocumentReader.java:187)
at org.springframework.ide.eclipse.beans.core.internal.model.BeansConfig$ToolingFriendlyBeanDefinitionDocumentReader.doRegisterBeanDefinitions(BeansConfig.java:1330)
at org.springframework.beans.factory.xml.DefaultBeanDefinitionDocumentReader.registerBeanDefinitions(DefaultBeanDefinitionDocumentReader.java:110)
at org.springframework.beans.factory.xml.XmlBeanDefinitionReader.registerBeanDefinitions(XmlBeanDefinitionReader.java:494)
at org.springframework.ide.eclipse.beans.core.internal.model.BeansConfig$2.registerBeanDefinitions(BeansConfig.java:402)
at org.springframework.beans.factory.xml.XmlBeanDefinitionReader.doLoadBeanDefinitions(XmlBeanDefinitionReader.java:391)
at org.springframework.beans.factory.xml.XmlBeanDefinitionReader.loadBeanDefinitions(XmlBeanDefinitionReader.java:335)
at org.springframework.ide.eclipse.beans.core.internal.model.BeansConfig$2.loadBeanDefinitions(BeansConfig.java:388)
at org.springframework.beans.factory.xml.XmlBeanDefinitionReader.loadBeanDefinitions(XmlBeanDefinitionReader.java:303)
at org.springframework.ide.eclipse.beans.core.internal.model.BeansConfig$3.call(BeansConfig.java:445)
at org.springframework.ide.eclipse.beans.core.internal.model.BeansConfig$3.call(BeansConfig.java:1)
at java.util.concurrent.FutureTask$Sync.innerRun(Unknown Source)
When compiling the application with Ant script and starting the server, everything works fine, so the problem is limited to Eclipse and Spring IDE. Both my Ant and Eclipse configurations use the same Spring library. addConstructorArg method still seems to exist in the newest version of Spring, so I am puzzled by this error. What could be causing this problem?
I believe this is because Spring Tools Suite comes with it's own spring libraries. So for the XML parsing and validation it does not use libraries on your project classpath.
Please see STS-3679
Check your XML configuration files for both Spring and Spring security.
Do you have correct URLs in xsi:schemaLocation, like:
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.5.xsd

Has anyone tried datanucleus JPA implementation with orientdb?

I am trying to implement Datanucleus JPA for orientdb for my java project. I am able to successfully make it work with datanucleus3.1.2, mongodb. but when I tried to do with orientdb, I read it works with 2.x (i guess ONLY 2.x at moment). I replaced all datanucleus 3.x jars with 2.x.
For mongodb I have following works fine
Persistence.createEntityManagerFactory("mongodb");
with persistence.xml
<persistence-unit name="mongodb">
<properties>
<property name="datanucleus.ConnectionURL" value="mongodb:localhost:27017/db"/>
<property name="datanucleus.storeManagerType" value="mongodb" />
<property name="datanucleus.autoCreateSchema" value="true" />
</properties>
</persistence-unit>
Has anyone able to get it work? How to create entity manager factory for orientdb?
How the persistence.xml should look like?
I keep getting
javax.persistence.PersistenceException: No Persistence provider for EntityManager named orientdb
at javax.persistence.Persistence.createEntityManagerFactory(Persistence.java:84)
at javax.persistence.Persistence.createEntityManagerFactory(Persistence.java:54)