Error configuring mongo and neo4j with spring boot 1.5.7 - spring

I am using MongoDb and Neo4j in my Spring Boot Application. I have recently updated by Spring Boot Gradle Plugin from 1.2.6 to 1.5.7.
I am having two config files one for mongo and other for neo4j. After updating the version of spring boot I found that #EnableMongoRepositories and #EnableNeo4jRepositories are showing following errors in their respective config files:
No constructor with 1 argument defined in class
'org.springframework.data.mongodb.repository.support.MongoRepositoryFactoryBean'
No constructor with 1 argument defined in class
'org.springframework.data.neo4j.repository.support.GraphRepositoryFactoryBean'
I am having following annotations in neo4j config:
#Configuration
#EnableNeo4jRepositories("<packagename>.neo4j.repository")
#EnableTransactionManagement
public class DatabaseConfigurationNeo4j
extends Neo4jConfiguration { ... }
and following annotations in mongo config:
#Configuration #Profile("!" + Constants.SPRING_PROFILE_CLOUD)
#EnableMongoRepositories("<packagename>.repository")
#Import(value = MongoAutoConfiguration.class)
#EnableMongoAuditing(auditorAwareRef = "springSecurityAuditorAware")
public class DatabaseConfiguration extends AbstractMongoConfiguration
{ ... }
If I remove these #EnableRepositories line from the files, these errors are removed but when I run it, the repositories bean are not creating. I think these lines are necessary but dont know how to remove this error.
Thank you.

updating spring-neo4j to 4.2.8 (not 5.0.0 as neo4j 5.0.0 will work with spring-boot 2.0 M and above) and spring-mongo to 1.10.6 solved the configuration issues.

Related

Spring boot error: Unable to load class 'com.mysema.codegen.model.Type'Unable to load class

Spring boot error: Unable to load class 'com.mysema.codegen.model.Type'Unable to load class 'com.mysema.codegen.model.Type'
SpringBoot: 2.6.8,
querydslVersion = '4.3.1'
Solution:
// update the query dsl version, e.g:
implementation 'com.querydsl:querydsl-core:5.0.0'

Unable to make field static final java.lang.invoke.MethodHandles$Lookup java.lang.invoke.MethodHandles$Lookup.IMPL_LOOKUP

I have a Spring Feign client which is sending POJO object to remote endpoint using POST and my application start-up fails with below exceptions.
java.lang.reflect.InaccessibleObjectException: Unable to make field static final java.lang.invoke.MethodHandles$Lookup java.lang.invoke.MethodHandles$Lookup.IMPL_LOOKUP accessible: module java.base does not "opens java.lang.invoke" to unnamed module #420a85c4
Below the dependencies I am using in my application.
java version: 17
spring boot version: 2.5.3
spring boot cloud version: 2020.0.3
spring boot starter openfeign version: 2.2.8.RELEASE
As recommended in https://github.com/OpenFeign/feign/issues/935, I had tried
workaround solution: Adding this jvm option '--add-opens java.base/java.lang.invoke=ALL-
UNNAMED' worked.
Any other alternative suggestion other than jvm argument are most welcome.
Force OpenFeign version to at least 11.7, which has this issue solved.
If you are using Spring Dependency Management plugin, then you can do it like this (Gradle example):
dependencyManagement {
dependencies {
dependencySet(group: 'io.github.openfeign', version: '11.7') {
entry 'feign-core'
entry 'feign-jackson'
entry 'feign-slf4j'
entry 'feign-soap'
entry 'feign-jaxb'
}
}
}
For me it worked to add the following JVM Option:
--add-opens java.base/java.lang.invoke=ALL-UNNAMED
For JDK 9+, if you use the JVM options to fix the problem, add another = into the JVM options:
e.g.
--add-opens=java.base/java.lang.invoke=ALL-UNNAMED
I have same error when i declare default method (method with implementation) in interface class marked with #FeignClient. I just remove default method and the error has disappeared

Spring boot 2.1 while loading external properties, application properties in classpath are ignored

I am having an application.properties in my main/resources folder. Now certain values I want to over-ride at runtime using an external properties file.
To do this I have added the following code:
class ServletInitializer extends SpringBootServletInitializer {
#Override
protected SpringApplicationBuilder configure(SpringApplicationBuilder application) {
application=application.properties('spring.config.location:/external/properties/,${catalina.base}/../config/config.properties')
application.build()
application.sources(Application)
}
}
With this change its reading the external file but completely ignoring the application.properties file (i.e any value present in application.properties only is not retained).
Spring boot version : 2.1.0.RELEASE
Groovy version : 2.5.3
JDK : 1.8
Note : This same code was working for spring boot version 1.5.10.RELEASE

Spring-boot #ImportResource ignored in Weblogic

I'm facing a strange issue while deploying a spring-boot legacy-war in weblogic-12c. The same war/application works in both mvn spring-boot:run (embedded-tomcat) / Standalone tomcat war deployment.
The #ImportResource configured in the main application is not getting loaded which is causing few bean-injection inconsistencies. Is there any known issue to be worked-around for deploying in weblogic12c?
Note: I've already tried below:
1. extends SpringBootServletInitializer implements WebApplicationInitializer
2. Separate inner-config class
#Configuration #ImportResource({
"classpath*:**/**my-applicationContext.xml"}) #ComponentScan(basePackages =
{"com.myapp"
})
SLF4J exclude in weblogic.xml
<wls:prefer-application-packages>
<wls:package-name>org.slf4j</wls:package-name>
<wls:package-name>com.google.common.*</wls:package-name>
</wls:prefer-application-packages>
The issue was with the Antlr pattern used for loading xml-appcontexts. Strangely the same expression worked in embedded tomcat / standalone tomcat.
The fix was to expand few of the *
#Configuration
#ImportResource({
"classpath*:mypackage/**my-applicationContext.xml"})
#ComponentScan(basePackages = {"com.myapp" })
Debug info:
AbstractBeanDefinitionReader (Line 216) - spring-beans-4.2.4

Jersey 2 + Spring 4 without web.xml/applicationContext.xml

I have 2 Maven projects:
project1 that contains my entities/services/DAOs, with a Java Spring (4.2.4) config (no XML)
project2 that is my RESTful API using Jersey (2.22.1), that contains the resources (controllers), Java configuration (extending ResourceConfig, no web.xml)
I would like to inject my services in my Jersey resources, here is what I did:
I added the Maven dependency to project1 in project2
I added the dependency jersey-spring3 to project2
I didn't change anything in my Jersey config class.
I run jetty (Maven plugin, no public static void main or any class to run the server).
First attempt: applicationContext.xml was required.
Second attempt: after adding an empty applicationContext.xml (to project2), my services are not found.
Third attempt: after adding <context:component-scan base-package="com.xxx.project1"/> to applicationContext.xml (package where my project1 Java Spring config lives), services are injected.
My question is how to get rid of the applicationContext.xml file?
I would like my Spring config from project1 to be detected automatically...
Some code:
The Spring configuration
#Configuration
#ComponentScan("com.xxx.project1.service")
public class SpringConfig {
}
The Jersey configuration
#ApplicationPath("/v1")
public class Application extends ResourceConfig {
public Application() {
packages("com.xxx.project2.filter",
"com.xxx.project2.resource");
register(RolesAllowedDynamicFeature.class);
}
}
Use a Spring WebApplicationInitializer to bootstrap the Spring components. You can see an example in this post.

Resources