I copied your spring security configuration and was able to reproduce the error.
Following line in the stacktrace gives the root cause of the exception:
at org.springframework.security.provisioning.InMemoryUserDetailsManager.createUser(InMemoryUserDetailsManager.java:59)
In InMemoryUserDetailsManager
class, createUser()
method, Spring checks if the user exists before creating an user. In your case you are adding two user with same username, hence there is an IllegalArgumentException
.
I added two users with different usernames and it started working fine.
I had the same problem. I fixed it deleting http.antMatchers("")
.The problem was "" - SpringSecurityFilterChain throws an error, because pattern could not be empty or null.
With java 11 please add this to pom file
<dependency>
<groupId>com.sun.xml.bind</groupId>
<artifactId>jaxb-core</artifactId>
<version>2.3.0.1</version>
</dependency>
<dependency>
<groupId>javax.xml.bind</groupId>
<artifactId>jaxb-api</artifactId>
<version>2.3.1</version>
</dependency>
<dependency>
<groupId>com.sun.xml.bind</groupId>
<artifactId>jaxb-impl</artifactId>
<version>2.3.1</version>
</dependency>
Simply, You can't create 2 users with same user name. But passwords can be same. Just rename the username
Fixed it by changing .antMatchers("/api/", "") to .antMatchers("/api/")
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With