Home  >  Article  >  Java  >  How to implement SpringBoot profile multi-environment switching

How to implement SpringBoot profile multi-environment switching

WBOY
WBOYforward
2023-05-17 10:04:111065browse

SpringBoot's profile multi-environment switching

1. Configure profile and build in the pom file

    
        
            dev
            
                
                true
            
            
                
                dev
                
                127.0.0.1:8848
                
                DEV
                
                127.0.0.1:8848
                DEV
            
        
        
            test
            
                
                test
                
                127.0.0.1:8848
                
                TEST
                
                127.0.0.1:8848
                TEST
            
        
        
            prod
            
                
                prod
                
                127.0.0.1:8848
                
                PROD
                
                127.0.0.1:8848
                PROD
            
        
    

    
        
            
                src/main/resources
                
                true
                
                    
                    application.yml
                    application-dev.yml
                    application-test.yml
                
            
            
                src/main/resources
                true
                
                
                    application.yml
                    application-${profiles}.yml
                
            
        
    

2. Create three files dev\test
How to implement SpringBoot profile multi-environment switching

3. Bootstrap source file content

spring:
  profiles:
    active: test

4. bootstrap-dev content

server:
  port: 8080
spring:
  profiles: dev

5. bootstrap-test content

server:
  port: 8080
spring:
  profiles: test

6. Switch
How to implement SpringBoot profile multi-environment switching

The above is the detailed content of How to implement SpringBoot profile multi-environment switching. For more information, please follow other related articles on the PHP Chinese website!

Statement:
This article is reproduced at:yisu.com. If there is any infringement, please contact admin@php.cn delete