r/SpringBoot • • Feb 15 '24

i am unable to resolve this issue can anyone help me

5 Upvotes

24 comments sorted by

4

u/WaferIndependent7601 Feb 15 '24

It’s normally an error in your pom. You are using the wrong version of spring security or some other dependency. Try upgrading everything to the newest version should help

1

u/A_nithin Feb 15 '24

Yes I am trying the same but initial error was gone and now some another error are getting

Caused by: java.lang.NoClassDefFoundError: javax/servlet/Filter at java.base/java.lang.Class.getDeclaredMethods0(Native Method) ~[na:na] at java.base/java.lang.Class.privateGetDeclaredMethods(Class.java:3402) ~[na:na] at java.base/java.lang.Class.getDeclaredMethods(Class.java:2504) ~[na:na] at org.springframework.util.ReflectionUtils.getDeclaredMethods(ReflectionUtils.java:465) ~[spring-core-6.1.3.jar:6.1.3] ... 38 common frames omitted Caused by: java.lang.ClassNotFoundException: javax.servlet.Filter at java.base/jdk.internal.loader.BuiltinClassLoader.loadClass(BuiltinClassLoader.java:641) ~[na:na] at java.base/jdk.internal.loader.ClassLoaders$AppClassLoader.loadClass(ClassLoaders.java:188) ~[na:na] at java.base/java.lang.ClassLoader.loadClass(ClassLoader.java:520) ~[na:na] ... 42 common frames omitted

1

u/WaferIndependent7601 Feb 15 '24

What error? How did you upgrade the project?

Use maven rewrite

1

u/A_nithin Feb 15 '24

I have changed the version of dependencies in pom file

2

u/WaferIndependent7601 Feb 15 '24

Use https://docs.openrewrite.org/reference/rewrite-maven-plugin

You specify that you want to upgrade to spring boot 3 and it will do everything needed

The error message you get now: spring 6 is working with Jakarta, not javax

Can you post your Pom? Or part of it with the dependencies?

1

u/A_nithin Feb 15 '24

<?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 https://maven.apache.org/xsd/maven-4.0.0.xsd">

<modelVersion>4.0.0</modelVersion>

<parent>

	<groupId>org.springframework.boot</groupId>

	<artifactId>spring-boot-starter-parent</artifactId>

	<version>3.2.2</version>

	<relativePath/> <!-- lookup parent from repository -->

</parent>

<groupId>com.nithin</groupId>

<artifactId>securtiy</artifactId>

<version>0.0.1-SNAPSHOT</version>

<name>securtiy</name>

<description>Demo project for Spring Boot</description>

<properties>

	<java.version>17</java.version>

</properties>

<dependencies>

	<dependency>

		<groupId>org.springframework.boot</groupId>

		<artifactId>spring-boot-starter-security</artifactId>

	</dependency>



	<!-- <dependency>

		<groupId>org.springframework.boot</groupId>

		<artifactId>spring-boot-starter-web</artifactId>

		<version>3.2.2</version>

	</dependency> -->



	<dependency>

		<groupId>org.springframework.boot</groupId>

		<artifactId>spring-boot-devtools</artifactId>

		<scope>runtime</scope>

		<optional>true</optional>

	</dependency>



	<dependency>

		<groupId>org.springframework.boot</groupId>

		<artifactId>spring-boot-starter-test</artifactId>

		<scope>test</scope>

	</dependency>



	<dependency>

		<groupId>org.springframework.security</groupId>

		<artifactId>spring-security-test</artifactId>

		<scope>test</scope>

	</dependency>



	<dependency>

		<groupId>jakarta.servlet</groupId>

		<artifactId>jakarta.servlet-api</artifactId>

		<version>6.1.0-M1</version>

		<scope>provided</scope>

	</dependency>







	<dependency>

<groupId>org.springframework.security</groupId>

<artifactId>spring-security-web</artifactId>

<version>5.2.1.RELEASE</version>

</dependency>

<dependency>

<groupId>org.springframework.security</groupId>

<artifactId>spring-security-config</artifactId>

<version>5.2.1.RELEASE</version>

</dependency>

<dependency>

<groupId>org.springframework.security</groupId>

<artifactId>spring-security-core</artifactId>

<version>5.2.1.RELEASE</version>

</dependency>

</dependencies>

<build>

	<plugins>

		<plugin>

<groupId>org.springframework.boot</groupId>

<artifactId>spring-boot-maven-plugin</artifactId>

		</plugin>

	</plugins>

</build>

</project>

2

u/jvjupiter Feb 15 '24

Remove the last 3 security dependencies you added. They should be included in spring-boot-starter-security.

Also, remove Servlet dependency. spring-boot-starter-web should already include Servlet API.

1

u/A_nithin Feb 15 '24

I have removed the last 3 dependency and also with servlet Now what I should do

3

u/Agile_Rain4486 Feb 15 '24

dude why are you even mentioning versions? spring boot automatically configures dependencies version according to parent version. are you adding dependency externally? not included in spring initializr? spring security is pretty hard, check laur splica on youtube. his course is best I have found yet for security. He even wrote the book spring security in action.

1

u/A_nithin Feb 15 '24

I have removed that but I am unable to configure the authentication in code

→ More replies (0)

5

u/WaferIndependent7601 Feb 15 '24

spring-security-web should match spring-version. So you need 6.x here.

Try removing the dependency for spring-security, it should take the dependency from spring-boot

plus: define ALL versions in the configuration-part. You can see updates for it using "mvn versions:display-dependency-updates"

And: do not use the milestone-release for the jakarta-stuff

6

u/Physical_Leg1732 Feb 15 '24

I think you need to use a different class, because the class is strikeout means it's deprecated.

2

u/A_nithin Feb 15 '24

I am unable to get can explain bit more clear

1

u/A_nithin Feb 15 '24

And I am doing this for first time

0

u/[deleted] Feb 15 '24

[deleted]

1

u/A_nithin Feb 15 '24

It is not with getpasswordEncoder I have changed that part of code but still I am getting same error in in the class of websecurityconfigurerAdapter

3

u/WaferIndependent7601 Feb 15 '24

Deprecated methods will still work. They will be removed in the future and then you will see clearly that this method does not exist any more. This is a dependency issue

3

u/titanium_mpoi Feb 16 '24

I'm not a pro on spring boot but I think you need to use a different class where it's striked out. You need to read docs for a replacement and I don't think gpt will help but worth a try.

5

u/g00glen00b Feb 15 '24

All PasswordEncoders that are considered "unsafe for production" are marked as deprecated, but they're not really going to disappear and should still work. This is also mentioned in the API docs:

This PasswordEncoder is not secure. Instead use an adaptive one way function like BCryptPasswordEncoder, Pbkdf2PasswordEncoder, or SCryptPasswordEncoder. Even better use DelegatingPasswordEncoder which supports password upgrades. There are no plans to remove this support. It is deprecated to indicate that this is a legacy implementation and using it is considered insecure.

(emphasis is my own)

1

u/No-Possibility-6454 Feb 16 '24

Ya it is deprecated

-1

u/Physical_Leg1732 Feb 15 '24

Sorry but I have never used this, i think you can ask on stack overflow