How do I get the #EnableOAuth2Sso annotation - spring

Upgraded to Spring Boot 2, now the #EnableOAuth2Sso annotation is missing because the import is now incorrect.
I found some docs on this issue:
https://github.com/spring-projects/spring-boot/issues/11032#issuecomment-372100443
but it doesn't say what to replace the import with. Thanks!

Same issue and found you have to add the Spring Security OAuth2 AutoConfigure dependency.

Related

Migrate #EnableCircuitBreaker and #EnableEurekaClient to Spring Cloud 2022.0.1

I upgraded Spring Cloud version to 2022.0.1 and I get error for imports not found:
import org.springframework.cloud.client.circuitbreaker.EnableCircuitBreaker;
import org.springframework.cloud.netflix.eureka.EnableEurekaClient;
Application class:
#EnableEurekaClient
#EnableCircuitBreaker
Do you know how I can properly import them or upgrade them?
since Spring boot 2.5.12 #EnableCircuitBreaker is Deprecated, So you don't need to use it.
Also, this happened to #EnableEurekaClient and there is no need to annotate it
Just add these two dependencies to the project
spring-cloud-starter-circuitbreaker-resilience4j
org.springframework.cloud:spring-cloud-starter-netflix-eureka-client

ComponentScan does not find own custom annotations after update from Spring Boot 2.0.3 to 2.2.4

Prior to the update from Spring Boot 2.0.3 to 2.2.4 we had some annotations like the following example:
import org.springframework.stereotype.Component;
#Component
public #interface Adapter {
}
During ComponentScan classes annotated with this Adapter annotation got picked up and added to the Spring context. After the update there are now org.springframework.beans.factory.NoSuchBeanDefinitionException: No qualifying bean of type 'XY' available.
According to a passage in the Terminology of the Spring Annotation Programming Model regarding Stereotype Annotations our approach should work:
Any component annotated with #Component is a candidate for component scanning. Similarly, any component annotated with an annotation that is itself meta-annotated with #Component is also a candidate for component scanning.
I read through the release notes of Spring Boot 2.1 and 2.2 and the release notes of the Spring Framework 5.1 and 5.2, but found nothing that the behaviour of stereotype annotations changed in this point.
When I annotate the classes with a Spring provided stereotype annotation (in addition to our own annotation) they get picked up by the ComponentScan.
I also tried to set a custom filter in a #ComponentScan like this
#ComponentScan(includeFilters = #ComponentScan.Filter(type = FilterType.ANNOTATION,
classes = Adapter.class))
but still got the NoSuchBeanDefinitionException
At last I stumbled upon this "Enhancement" in the Spring Framework and wonder if this could be the root of my problem.
So nothing worked so far and I would be glad if someone could point me in a direction that restores the original behaviour that our own stereotype annotations are working again. Thanks in advance.
After taking a closer look at the Spring Stereotype annotations adding #Retention(RetentionPolicy.RUNTIME) to our annotations solved the issue. The classes with our own annotations get picked up by ComponentScan again.
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import org.springframework.stereotype.Component;
#Retention(RetentionPolicy.RUNTIME)
#Component
public #interface Adapter {
}

Enable Actuator health endpoint without enabling auto config

In my project, I don't want to use #EnableAutoConfiguration. My Application.java has #ComponentScan, #Configuration and #Import annotation.
I have added spring boot actuator dependency in my pom.xml. But, when I try to access http://<>/acutuator/health, I get 404. I believe I need to specify some config class as part of Import annotation. I would need help in figuring out what that config would be.
#EnableAutoConfiguration makes Spring guess configuration based on the classpath, and that's what spring boot all about. If you find that specific auto-configuration classes that you do not want are being applied, you can use the exclude attribute of #EnableAutoConfiguration to disable them. For example:
#EnableAutoConfiguration(exclude={DataSourceAutoConfiguration.class})

An Authentication object was not found in the SecurityContext issue in Spring boot 1.5.9 and OAuth2

i was trying out with the sample application Spring Boot REST API Security with OAuth2 from
https://gigsterous.github.io/engineering/2017/03/01/spring-boot-4.html and it works fine, the sample uses spring boot 1.4.0.RELEASE, but when i switch to 1.5.9.RELEASE, i get this Authentication object not found issue. i have searched online for an answer and couldn't come up with anything close to resolve the issue. some people say that the order of filter chain is the cause. but none seem to be able to come up with a solution.
any help is appreciated.
i found the solution:
#Configuration
#EnableWebSecurity
#EnableGlobalMethodSecurity(prePostEnabled = true)
#Order(SecurityProperties.ACCESS_OVERRIDE_ORDER)
public class WebSecurityConfig extends WebSecurityConfigurerAdapter {
adding the #Order annotation resolve the issue. now i can use 1.5.9.RELEASE. I found it from https://github.com/spring-guides/tut-spring-boot-oauth2/tree/master/auth-server

Spring Boot multiproject Spring Data Jpa

I have a three module Spring Boot App. I've a problem when I try to add a Custom repositoryFactoryBeanClass and when i do that i get the following error:
No constructor with 0 arguments defined in class
'org.springframework.data.jpa.datatables.repository.DataTablesRepositoryFactoryBean'
My annotation is:
#EnableJpaRepositories(repositoryFactoryBeanClass =
DataTablesRepositoryFactoryBean.class, basePackages =
"xxx.xxxxxxx.xxxx.xxxxx.repositories")
I have three modules: web, entity/repository and service.
Thanks.
I was able to solve this by upgrading Spring Boot version to 1.5.4.RELEASE. Please refer this thread for more details https://github.com/darrachequesne/spring-data-jpa-datatables/issues/50
Finally,I changed #EnableJpaRepositories to
#EnableJpaRepositories(basePackages = "xxxx.xxxx.xxxxx.repositories", repositoryBaseClass = DataTablesRepositoryImpl.class)

Resources