Spring Security: How to change default user and password?

Viewed 18512

I have Spring Security in my pom.xml, and Spring Security is automatically configured with a default user and generated password:

<dependency>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-security</artifactId>
</dependency>

How do I change the default user and password?

5 Answers
#add these lines in application.properties
    spring.security.user.name=username
    spring.security.user.password=password

Add below properties in application.properties

spring.security.user.name= user_name
spring.security.user.password= user_password

where "user_name" will be the user and "user_password" will be the password.

These will not work with old version of spring boot, I was using 1.5.11.RELEASE and these properties were not working, After moving to 2.1.8.RELEASE, these properties work fine.

check your pom.xml

<parent>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-parent</artifactId>
        <version>2.1.8.RELEASE</version>
        <relativePath/> <!-- lookup parent from repository -->
    </parent>

spring.security.user.name=username
spring.security.user.password=password
Related