I want to extend WebSecurityConfigurerAdapter but it had been deprecated - spring

I'm trying to code a website using spring boot(security, jpa, web...) and i'm following this tutorial.
And in the minute : 1:05:25 , he needs to extend the WebSecurityConfigurerAdapter, but it had been deprecated in the last spring boot versions, so he changes the version in his "pom.xml" from :
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.7.3</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>
To :
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.6.5</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>
Then he saves all and updtaes the project. And when I do the same I get errors in my pom.xml file in the parent tag:
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.7.3</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>
with the error : Coul not read maven project ...
And I get an error in this dependancy :
<dependency>
<groupId>com.mysql</groupId>
<artifactId>mysql-connector-j</artifactId>
<scope>runtime</scope>
</dependency>
The error is :
3.0.0+
The <dependency> element contains information about a dependency of the project.
Source: maven-4.0.0.xsd`
I also get this error in my console :
APPLICATION FAILED TO START
***************************
Description:
Failed to configure a DataSource: 'url' attribute is not specified and no embedded datasource could be configured.
Reason: Failed to determine a suitable driver class
Action:
Consider the following:
If you want an embedded database (H2, HSQL or Derby), please put it on the classpath.
If you have database settings to be loaded from a particular profile you may need to activate it (no profiles are currently active).
While in the video, he doesn't get errors at all.
So I would like to solve the problem by modifying something in my pom.xml and keeping that application.

Related

resolve dependencies for maven project spring

pom.xml admin-service
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.7.3</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>
<groupId>com.springframework</groupId>
<artifactId>sai-edm-adminpanel</artifactId>
<version>0.0.1-SNAPSHOT</version>
<name>sai-edm-adminpanel</name>
<description>sai-edm-adminpanel</description>
<properties>
<java.version>17</java.version>
</properties>
pom.xml authorization service(which depends on the admin service)
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.7.3</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>
<groupId>com.springframework</groupId>
<artifactId>sai-edm-auth</artifactId>
<version>0.0.1-SNAPSHOT</version>
<name>sai-edm-auth</name>
<description>sai-edm-auth</description>
<properties>
<java.version>17</java.version>
<spring-cloud.version>Greenwich.RELEASE</spring-cloud.version>
</properties>
<dependencies>
<dependency>
<groupId>com.springframework</groupId>
<artifactId>sai-edm-adminpanel</artifactId>
<version>0.0.1-SNAPSHOT</version>
<scope>compile</scope>
</dependency>
when deploying the project gives me an error "Failed to execute goal on project sai-edm-auth: Could not resolve dependencies for project com.springframework:sai-edm-auth:jar:0.0.1-SNAPSHOT: Could not find artifact com.springframework:sai-edm-adminpanel:jar:0.0.1-SNAPSHOT in spring-milestones (https://repo.spring.io/milestone) -> [Help 1]"
The project is launched locally, the problem is only when deploying, tell me what could be the problem, please
Firstly, you cannot use the groupId "com.springframework" at it is not yours. See the Maven Guide. So for both artifacts sai-edm-adminpanel and sai-edm-adminpanel change the groupId to something you own.
Secondly, remove the compile scope line.
Thirdly, make sure that you have sai-edm-adminpanel artifact installed in your local m2 repository. You can find your local repo under ~/.m2/repository/. If you cannot find it there, you first must install it by going to the sai-edm-adminpanel pom.xml and running mvn clean install.

PCF Unable to use Config Server and Service Registry together in an Application

I am trying to bind the PCF Config Server and PCF Service registry in the same Application and push the app . However I get an error while the application is starting . The problem is due to the application unable to send the Hertbeat information and it fails with unable to refresh cache.
If i bind config server alone and Service registry alone it works but when both the services are bound it fails.
Any help with this is appreciated
The dependencies are as follows
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.0.5.RELEASE</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>
<dependency>
<groupId>io.pivotal.spring.cloud</groupId>
<artifactId>spring-cloud-services-starter-service-registry</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-openfeign</artifactId>
</dependency>
<dependency>
<groupId>io.pivotal.spring.cloud</groupId>
<artifactId>spring-cloud-services-starter-config-client</artifactId>
</dependency>
This was resolved after gave the Service registry to take the path using the following configuration
spring.cloud.services.registrationMethod=route

Spring project error using thymeleaf, Compilation failure. How can I fix this?

I'm pretty new at Spring framework, and I try to start a project for practice.
But I have an error and I have no idea how to fix this.
I've created a new Spring project in IntelliJ Idea, with Spring Initializr option (In Intellij, not with start.spring.io ). I added only 2 dependedncies for start (Web and Thymeleaf), but it throws error for Thymeleaf dependency if i run it with
'mvn spring-boot:run' command.
My spring project is "empty" , I have no controllers, beans, jpa entites, etc.. but it i think it shound run in this way too. I just wanted to make sure if it works if I run it.
If I create a same project, without Thymeleaf dependency (only Web dependency), it starts correctly on localhost.
I'm using Java 9.0.4 and Apache Maven 3.5.3
My error log
pom.xml:
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0
http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.example</groupId>
<artifactId>demo_thymeleaf</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>jar</packaging>
<name>demo_thymeleaf</name>
<description>Demo project for Spring Boot</description>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.0.0.RELEASE</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
<java.version>9</java.version>
</properties>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-thymeleaf</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
</build>
I solved it with deleting the whole C\Users\user.m2 directory.
After then with 'mvn spring-boot:run' it started successfully on localhost.
But I've got one more question:
When I run it, at terminal there are a couple of Warning messages.
Spring application runs anyway, but is there something to do with these messages?
Warning messages during Spring application run.

Spring Boot project in IntelliJ IDEA stops working after reboot

This is probably a newbie question, but I am not able to sort things out.
I've created a Spring Boot JAR-based Maven project using the Spring Initializr interface in IntelliJ IDEA. Its dependencies on Web and JDBC; an embedded instance of Tomcat is used to run the project.
I also have a couple of other Maven dependencies I add without problems from the relevant dialog; I also manually add the Apache Phoenix thin client JAR, that includes a copy of Logback (I am not able to get their Maven repository to work, but I don't think this is relevant to this question).
I am able to run the project flawlessly; after a system reboot (I am on Windows), a cascade of errors follows. First and foremost an exception signaling a conflict between Logback comes:
Exception in thread "main" java.lang.IllegalArgumentException: LoggerFactory is not a Logback LoggerContext but Logback is on the classpath. Either remove Logback or the competing implementation (class org.slf4j.impl.Log4jLoggerFactory loaded from [...]). If you are using WebLogic you will need to add 'org.slf4j' to prefer-application-packages in WEB-INF/weblogic.xml: org.slf4j.impl.Log4jLoggerFactory.
I would not like to alter the Phoenix client JAR; I am able to follow the instructions to replace the Spring dependency on Logback with another logger (log4j2 for example), but then the embedded Tomcat fails to create the container.
To get back to work, I have to recreate the project from scratch.
Could you please point me in the right direction to pinpoint the actual problem? Thank you.
Post scriptum: I am attaching the content of my pom.xml, apart from some potentially identifying information.
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>[RETRACTED]</groupId>
<artifactId>[RETRACTED]</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>jar</packaging>
<name>[RETRACTED]</name>
<description>[RETRACTED]</description>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>1.5.9.RELEASE</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
<java.version>1.8</java.version>
</properties>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-jdbc</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
</build>
</project>
Firstly, rather than adding the apache phoenix client (or any other dependencies) manually you should add them to your maven pom.xml, so maven resolves the dependency at build time. If your project has dependencies which maven is failing to resolve this is a separate issue which you need to resolve, but adding them manually is bad practice for a number of reasons.
Once you have added the phoenix client as a dependency, you need to explicitly exclude slf4j-log4j12 and log4j as part of the dependency declaration. The XML should look something like this:
<dependency>
<groupId>org.apache.phoenix</groupId>
<artifactId>phoenix-core</artifactId>
<version>4.13.1-HBase-1.3</version>
<exclusions>
<exclusion>
<groupId>log4j</groupId>
<artifactId>log4j</artifactId>
</exclusion>
<exclusion>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-log4j12</artifactId>
</exclusion>
</exclusions>
</dependency>
The reason these need excluded is that they are conflicting with the versions bundled in the spring-boot project
Hopefully this will sort your problem.

Missing #ConditionalBean on StormpathWebMvcAutoConfiguration.stormpathApplicationResolver

While trying to add Stormpath to my existing Spring-Boot application, I have the following error on startup.
java.lang.IllegalStateException: Error processing condition on com.stormpath.spring.boot.autoconfigure.StormpathWebMvcAutoConfiguration.stormpathApplicationResolver
...
Caused by: java.lang.IllegalArgumentException: #ConditionalOnMissingBean annotations must specify at least one bean (type, name or annotation)
My pom :
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>1.3.6.RELEASE</version>
<relativePath />
</parent>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<java.version>1.8</java.version>
<stormpath.version>1.1.1</stormpath.version>
</properties>
<dependencies>
<dependency>
<groupId>com.stormpath.spring</groupId>
<artifactId>stormpath-default-spring-boot-starter</artifactId>
<version>${stormpath.version}</version>
</dependency>
</dependencies>
The stormpath version 1.1.1 works with spring-booth 1.4. I solved the problem by changing the spring-boot-starter-parent version to 1.4.1.

Resources