What are analogs for classes from *autoconfigure.security.oauth2 and *security.oauth2 for Spring Boot 2.1.1.RELEASE? - spring

What are analogs for classes from *autoconfigure.security.oauth2 and *security.oauth2 for Spring Boot 2.1.1.RELEASE version of spring-boot-starter-parent?
They are removed in this version.
import org.springframework.boot.autoconfigure.security.oauth2.resource.ResourceServerProperties;
import org.springframework.boot.autoconfigure.security.oauth2.resource.UserInfoTokenServices;
import org.springframework.security.oauth2.client.OAuth2ClientContext;
import org.springframework.security.oauth2.client.OAuth2RestTemplate;
import org.springframework.security.oauth2.client.filter.OAuth2ClientAuthenticationProcessingFilter;
import org.springframework.security.oauth2.client.filter.OAuth2ClientContextFilter;
import org.springframework.security.oauth2.client.token.grant.code.AuthorizationCodeResourceDetails;
import org.springframework.security.oauth2.config.annotation.web.configuration.EnableOAuth2Client;

I think what you're missing is a dependency on spring-security-oauth2-autoconfigure to make your old setup work "seamlessly" with Spring Boot 2.1.1.RELEASE
<dependency>
<groupId>org.springframework.security.oauth.boot</groupId>
<artifactId>spring-security-oauth2-autoconfigure</artifactId>
<version>2.1.1.RELEASE</version>
</dependency>
That being said that project is maintenance mode and the recommended approach is to use the built in Spring Oauth support.

Related

import of amqp from org.springframework get error

I'm working on existing Scala project which using the spring framework and I need to import org.springframework.amqp but when I tried to build the project I get:
Error:(15, 28) object amqp is not a member of package
org.springframework import org.springframework.amqp
It is really strange since I can see it in the formal website and I can see it in lot of examples in the web.
Any idea what is the problem?
A Maven dependency was missing. This is what I was need to add:
<dependency>
<groupId>org.springframework.amqp</groupId>
<artifactId>spring-amqp</artifactId>
<version>2.1.2.RELEASE</version>
</dependency>

No #NotBlank validator for type String

I keep getting validator error for quite simple configuration class
import lombok.Data;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.stereotype.Component;
import org.springframework.validation.annotation.Validated;
import javax.validation.constraints.NotBlank;
#Component
#Data
#Validated
#ConfigurationProperties(prefix = "test")
public class TestProperties {
#NotBlank
String uri;
}
Error is self explaining:
javax.validation.UnexpectedTypeException: HV000030: No validator could be found for constraint 'javax.validation.constraints.NotBlank' validating type 'java.lang.String'. Check configuration for 'uri'
But according to spring boot documentation this should work.
I had the same issue and solved it.
As Yogi stated in his answer, there are two implementations:
import javax.validation.constraints.NotBlank;
and
import org.hibernate.validator.constraints.NotBlank;
Switching from the javax implementation to the hibernate one solved the issue.
Since I didn't use Spring boot, I had to add to my pom.xml:
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-validator</artifactId>
<version>5.2.4.Final</version>
</dependency>
According to Spring-Boot documentation and maven central repo the:
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
has the validator included. If you have not spring-boot-starter-web included to your dependencies you can just add the validator:
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-validation</artifactId>
</dependency>
I saw a similar question outside this forum and discovered that the error comes up whenever you try to put #NotBlank annotation on any non-string type field. In my case, the javax.validation.UnexpectedTypeException came up when I annotated a field of type Byte with #NotBlank. So I imported javax.validation.constraints.NotNull, changed the annotation on the Byte field to #NotNull and the error disappeared.
I previously tried replacing import javax.validation.constraints.NotBlank; with import org.hibernate.validator.constraints.NotBlank; to kill the error, but I got a deprecation warning. Programmers are discouraged from using deprecated program elements, so I advise that you use #NotNull annotation instead.
To understand the differences between #NotBlank and #NotNull, see this StackOverflow thread. That way, you get to decide if #NotNull fits your use case.
In my case, it worked okay when running as a standalone application, but gave this same error when running as a WAR; in order to make it work, it was necessary to explicitly import the hibernate-validator as a dependency in order to make it work when running as a WAR:
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-validator</artifactId>
<version>7.0.2.Final</version>
</dependency>
<dependency>
<groupId>org.hibernate.validator</groupId>
<artifactId>hibernate-validator-annotation-processor</artifactId>
</dependency>
You can use below options,which works with Spring JPA:
org.hibernate.validator.constraints.NotBlank
javax.validation.constraints.NotNull
I have always used #NotNull.
I think the corresponding POM code is
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-jpa</artifactId>
</dependency>

Intellij can’t import dependency import by spring-boot-starter

I want use org.yaml.snake.Yaml in my springboot application. Since the spring-boot-starter has already included the snakeYML. thus I don't need import the org.yaml.snake.Yaml again in my pom.xml file.
when I type import org.yaml.snake.Yaml in source code, eclipse can exactly import it. However, when I use the Intellij it can't import the package.
As I edit the pom.xml and add below:
<dependency>
<groupId>org.yaml</groupId>
<artifactId>snakeyaml</artifactId>
<version>1.10</version>
</dependency>
It works fine!
I wander is this a bug of intellij?

spring boot guide missing autoconfigure

I am just going through the Spring Boot guide Tutorial:
https://spring.io/guides/gs/spring-boot/
In the Step while adding the Unittests seems broken.
The class misses some Imports:
import org.springframework.boot.test.autoconfigure.web.servlet.AutoConfigureMockMvc;
import org.springframework.test.context.junit4.SpringRunner;
Of course I can search and add the maven packages manually, but I want to know if this package should be enough? If though, what could be wrong in my code?
The guide says, this is enough:
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
Thanks for any infos!
OK... bottom line it was a stupid typo...
in pom.xml
in <parent> tag
I used the <version>1.2.3 ....
It works with <version>1.5.3 ....
Sry for the inconvienece.

Spring Framework 4.3.1 mail not resolved

I updated Spring Framework to 4.3.1, now I am getting an error:
The import cannot be resolved
for the following imports:
import org.springframework.mail.MailException;
import org.springframework.mail.SimpleMailMessage;
import org.springframework.mail.javamail.JavaMailSenderImpl;
import org.springframework.mail.javamail.MimeMessageHelper;
I have the following libraries for springframework 4.3.1;
spring-core-4.3.1.RELEASE.jar,
aop, aspects, beans, context, context-support,expression, instrument,
instrument-tomcat, jdbc, jms, messaging, orm, tx, websocket
I am not using Maven. Others: Java 8, Liferay 4.3.1, Hibernate 5.2. How can I fix it?
The mail library is found in spring-context-support so download spring-context-support-4.3.1.RELEASE.jar and add that in your classpath
Without maven you may know that you must place the jar in classpath. Follow the jar.
Java Mail Jar
Check those steps on link above and you'll get it.
Spring Mail Integration
If work, tell us a feedback.
Regards
If it was Maven you could add the following to your dependencies:
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-context-support</artifactId>
</dependency>

Resources