Maven orqali SpringBoot-da faol profilni sozlash

Maven 3 yordamida Spring Boot dasturida faol profilni o'rnatmoqchiman Pom.xml da rivojlanish uchun standart faol profil va spring.profiles.aktif xususiyatini o'rnatdim:


    
        development
        
            development
        
        
            true
        
    

ammo har safar dasturni ishga tushirganimda, jurnalga quyidagi xabarni olaman:

No active profile set, falling back to default profiles: default

va SpringBoot profili default sifatida o'rnatiladi (application.properties dastur-development.properties o'qiydi)

Mening Mavzum profilimdan foydalanib, mening SpringBoot faol profilimni o'rnatish uchun nima qilishim kerak? Har qanday yordam juda yuqori baholanadi.

12
qo'shib qo'ydi muallif Adam Siemion, manba

6 javoblar

Maven profili va Bahor profili ikkita butunlay boshqa narsadir. Sizning pom.xml siz yaratish jarayonida mavjud bo'lgan spring.profiles.active o'zgaruvchisini belgilaydi, lekin ish vaqtida emas. Shuning uchun faqat standart profil faollashtirilgan.

Maven profilini bahor bilan qanday bog'lash mumkin?

Yaratilgan o'zgaruvchining amaliyotga o'tkazilishi uchun uni ishga tushirishingiz kerak.

  1. Define a placeholder in your application.properties:

    [email protected]@
    

    The @[email protected] variable must match the declared property from the Maven profile.

  2. Enable resource filtering in you pom.xml:

    
        
            
                src/main/resources
                true
            
        
        …
    
    

    When the build is executed, all files in the src/main/resources directory will be processed by Maven and the placeholder in your application.properties will be replaced with the variable you defined in your Maven profile.

Qo'shimcha ma'lumot uchun mening postga o'tishingiz mumkin . Ushbu foydalanish hollari.

26
qo'shib qo'ydi
Maven buyrug'i orqali birlik sinovlari uchun profilni yoqishning bir yo'li bormi? Ehtimol bu savol uchun fikringiz bor.
qo'shib qo'ydi muallif Patrick, manba

Spring boot maven plaginini dan foydalaning:

  
  ...
  
    ...
    
      ...
      
        org.springframework.boot
        spring-boot-maven-plugin
        1.5.1.RELEASE
        
          
            foo
            bar
          
        
        ...
      
      ...
    
    ...
  
  ...

4
qo'shib qo'ydi

Siz quyidagi buyruqni ishlatishingiz mumkin. Bu erda bahor profili local yordamida ishlatmoqchiman:

spring-boot: ishga tushirish -Drun.jvmArguments = "- Dspring.profiles.active = local"

4
qo'shib qo'ydi
Eng yaxshi javob! Men uchun maven 3.5.2 + java 1.8 + spring-boot-1.5.9.RELEASE-dan Mac OS 10.13.3 da ishlagan.
qo'shib qo'ydi muallif user674669, manba
men uchun ishlamaydi
qo'shib qo'ydi muallif maddob, manba

Yoki osonlik bilan:

mvn spring-boot:run -Dspring-boot.run.profiles={profile_name}
2
qo'shib qo'ydi

Rivojlanayotganda ma'lum bir Maven profilini faollashganda Spring Boot profilini faollashtiring. rejimlarni ishlatishingiz kerak xususiyati Maven profilidagi bahor-boot-maven-plugin :


    <...>
    
        
            development
            
                true
            
            
                
                    
                        org.springframework.boot
                        spring-boot-maven-plugin
                        
                            
                                development
                            
                        
                    
                
            
        
    
    </...>

Spring Boot va Maven development profilidan foydalanish uchun quyidagi buyruqni ishga tushirishingiz mumkin:

mvn spring-boot:run -Pdevelopment

Agar biron-bir Spring Boot profilini bir xil profil nomiga ega bo'lgan Maven profiliga joylashtirishni istasangiz, bitta Maven profilini belgilashingiz va Maven xususiyatlarining mavjudligi aniqlanishi mumkin. Bu xususiyat mvn buyrug'ini ishlatishingiz kerak bo'lgan yagona narsa bo'lishi kerak Profil quyidagicha ko'rinadi:

    
        spring-profile-active
        
            
                my.active.spring.profiles
            
        
        
            
                
                    org.springframework.boot
                    spring-boot-maven-plugin
                    
                        
                            ${my.active.spring.profiles}
                        
                    
                
            
        
    

And Spring Boot va Maven development profilidan foydalanish uchun quyidagi buyruqni ishga tushirishingiz mumkin:

mvn spring-boot:run -Dmy.active.spring.profiles=development

yoki:

mvn spring-boot:run -Dmy.active.spring.profiles=integration

yoki:

 mvn spring-boot:run -Dmy.active.spring.profiles=production

Va shuning uchun ...

Ushbu turdagi konfiguratsiya ba'zi vazifalarni bajarish yoki ayrim narsalarni qadrlash uchun yuborilgan my.active.spring.profiles xususiyatiga tayanadigan umumiy Maven profilidagi kabi mantiqan to'g'ri keladi.
Misol uchun, men dasturni paketlaydigan va tanlangan atrof-muhitga xos docker tasvirini yaratuvchi umumiy Maven profilini sozlash uchun bu usuldan foydalanaman.

0
qo'shib qo'ydi

Springboot ilovasi uchun profillar o'rnatishning bir necha yo'li mavjud.

  1. You can add this in your property file:

    spring.profiles.active=dev
    
  2. Programmatic way:

    SpringApplication.setAdditionalProfiles("dev");
    
  3. Tests make it very easy to specify what profiles are active

    @ActiveProfiles("dev")
    
  4. In a Unix environment

    export spring_profiles_active=dev
    
  5. JVM System Parameter

    -Dspring.profiles.active=dev
    
0
qo'shib qo'ydi