Spring MVC Neo4jConfiguration class not found - spring

I am learning Spring MVC. I want to extend the Neo4jConfiguration class but it is not available. I imported the following dependency:
<dependency>
<groupId>org.springframework.data</groupId>
<artifactId>spring-data-neo4j</artifactId>
<version>4.2.4.RELEASE</version>
</dependency>
and after that I have reimported the libraries from maven. As I know I should now be able to extend the Neo4jConfiguration class. What is the problem? Thank you!

Neo4jConfiguration has been dropped from Spring Data Neo4j 4.2.
You can refer to the 'Configuring a Simple Spring Application' and 'Configuring Web Applications' in the Upgrading to Spring Data Neo4j 4.2 for a quick configuration without it.
The code sample they provide for simple configuration is:
#Configuration
#EnableNeo4jRepositories(basePackages = "org.neo4j.example.repository")
#EnableTransactionManagement
public class MyNeo4jConfiguration {
#Bean
public SessionFactory sessionFactory() {
// with domain entity base package(s)
return new SessionFactory("org.neo4j.example.domain");
}
#Bean
public Neo4jTransactionManager transactionManager() {
return new Neo4jTransactionManager(sessionFactory());
}
}

Related

Application failed to start after spring boot version upgrade from 2.1.18.RELEASE to 2.2.0.RELEASE

When we upgrade the spring-boot-starter-parent version from 2.1.8.RELEASE to 2.2.0.RELEASE, the application is not loading few beans. Due to this, application is failing. #PostConstuct is not able to add BCFIPS Provider in security provider.
#Configuration
#Slf4j
#ComponentScan(basePackages = "com.xxx.yyy.ekms.sdk")
#ConditionalOnProperty(name = "ekms.enabled", havingValue = "true")
public class EKMSClientSdkConfiguration extends ClientConfiguration
{
#PostConstruct
public void addSecurityProvider()
{
Security.addProvider(new BouncyCastleFipsProvider());
}
#Bean
public ApiClientBuilder apiClientBuilder()
{
return new DefaultApiClientBuilder();
}
}
Also, apiClientBuilder bean is not getting created.
The EKMSClientSdkConfiguration is extending ClientConfiguration, which is coming as part of another application jar. This class is not having any annotation.
public abstract class ClientConfiguration {
public ClientConfiguration()
{
}
public abstract void addSecurityProvider();
#Bean
public EKMSClient restClient() {
return new EKMSRestClientImpl(this.apiClient());
}
#Bean
public ApiClient apiClient() {
return Configuration.getDefaultApiClient();
}
}
In our case, EKMSClientSdkConfiguration bean is not getting created and the #PostConstruct is also not getting executed.
I went through the Spring Boot 2.2.RELEASE notes which is pointing to Spring Framework 5.2 upgrade guide. Here, I learned that spring boot 2.2.0 RELEASE is using Spring framework 5.2. In Spring framework 5.2, we have many changes.
It looks like this is the root cause of bean not getting loaded, but I am not sure about it.
Any help will be appreciated. Let me know if additional information is needed.
I found spring.main.lazy-initialization=true property in my application which was causing the above issue. When I removed it from the application.properties, This issue is resolved. This is the major change which was introduced in 2.2.0.RELEASE of spring boot

How to correctly handle "FeignException$ServiceUnavailableException" with fallback and without deprecated #EnableCircuitbreaker annotation

When using OpenFeign I implement fallbacks returning empty results so lists should simply appear as being empty. E.g. such as
#FeignClient(name = "objects", fallback = ObjectsClientFallback.class)
public interface ObjectsClient {
#RequestMapping("/objects/count")
Long count();
}
and
#Component
public class ObjectsClientFallback implements ObjectsClient {
#Override
public Long count() {
return 0L;
}
}
However, if the service is not started the application produces the ServiceUnavailableException when calling objectsClient.count() instead of using the fallback.
What is the correct way to use the fallback as #EnableCircuitBreaker has been deprecated recently? I do not want to add try-catch blocks if possible, especially in the context of lambdas or wrap this in service methods.
The application uses the #EnableDiscoveryClient annotation, like so
#SpringBootApplication
#EnableJpaRepositories
#EnableFeignClients
#EnableDiscoveryClient
#ServletComponentScan
public class Application {
//..
}
I've seen this question and checked the mentioned documentation, but it didn't help. Library versions are Spring-Boot 2.6.2 and Spring-Cloud 2021.0.0
Ended up using resilience4j for spring cloud.
Next to feign.circuitbreaker.enabled=true in application.properties which sets up a circuitbreaker with a default config.
One can add a custom configuration like this:
#Configuration
public class FeignConfiguration {
#Bean
public Customizer<Resilience4JCircuitBreakerFactory> circuitBreakerFactoryCustomizer() {
CircuitBreakerConfig circuitBreakerConfig =
CircuitBreakerConfig.custom()
.ignoreException(FeignException.ServiceUnavailable.class::isInstance)
.build();
return circuitBreakerFactory -> circuitBreakerFactory
.configure(builder -> builder.circuitBreakerConfig(circuitBreakerConfig),
ObjectsClient.class.getSimpleName());
}
}
Also, the resilience4j dependency needs to be in place, here a maven pom.xml is used.
<project>
<!-- .. -->
<dependencies>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-openfeign</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-circuitbreaker-resilience4j</artifactId>
</dependency>
</dependencies>
That way you can replace the deprecated hystrix implementation and remove the #EnableCircuitBreaker annotation.
In case you want a more fine-grained setup, here are is a discussion how to implement fallback with resilience4j via default methods.

SpringBoot - SpringFox Starter 3.0.0 - Unable to detect WebFlux RouterFunction

I am using SpringBoot WebFlux Springfox-starter for the project.
The issue is this not detecting the RouterFunction methods. The above methods are detecting without any issues but it is not working for RouterFunctions.
#Bean
public RouterFunction<ServerResponse> route(GreetingHandler greetingHandler) {
return RouterFunctions
.route(RequestPredicates.GET("/hello")
.and(RequestPredicates.accept(MediaType.TEXT_PLAIN)),
greetingHandler::hello);
}
#Component
public static class GreetingHandler {
public Mono<ServerResponse> hello(ServerRequest request) {
return ServerResponse.ok()
.contentType(MediaType.TEXT_PLAIN)
.body(BodyInserters.fromValue("Hello, SpringFox!"));
}
}
https://github.com/springfox/springfox
<dependency>
<groupId>io.springfox</groupId>
<artifactId>springfox-boot-starter</artifactId>
<version>3.0.0</version>
</dependency>
I have hosted the entire project in the below location. Please let me know if anyone experience the same or additional configuration missing here.
https://github.com/chamithchathuka/demowebflux-2
https://github.com/chamithchathuka/demowebflux-2/tree/master

How to make OpenApi UI work in Payara Micro

I have followed this tutorial Swagger UI on MicroProfile OpenAPI but simply adding the below to a pom.xml file of a Payara micro application does not add /openapi-ui, only /openapi works. Is there something else that is required or is it not possible with Payara Micro to have OpenApi UI.
<dependency>
<groupId>org.microprofile-ext.openapi-ext</groupId>
<artifactId>openapi-ui</artifactId>
<version>1.1.2</version>
</dependency>
My problem was the Application config class. I had to change
from:
#ApplicationPath("/api/v1")
public class JAXRSConfiguration extends Application {
public Set<Class<?>> getClasses() {
Set<Class<?>> s = new HashSet<>();
s.add(MyResource.class);
return s;
}
}
to
#ApplicationPath("/api")
public class JAXRSConfiguration extends Application {
}
Somehow overriding the getClasses() method and adding /v1 to the application path was messing with the openApi-ui configurations.

SpringBoot application monitoring Adding Timed annotation cause to error

I'm implementing micrometer to spring web project. While trying to add #Timed annotation. Prior to add #Timed i'm supposed to create TimedSpect bean. But it says could not autowire no bean of MeterRegistry type found
#Configuration
public class MetricsCofiguration {
#Bean
public TimedAspect timedAspect(MeterRegistry registry) {
return new TimedAspect(registry);
}
}
Not sure if you still need this answer but this is what i tried and its working fine.
#Configuration
#EnableAspectJAutoProxy
public class TimedConfiguration {
#Autowired
MeterRegistry registry;
#Bean
public TimedAspect timedAspect(MeterRegistry registry) {
return new TimedAspect(registry);
}
}
Make sure you have below starter dependency in your pom.
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-aop</artifactId>
</dependency>

Resources