2016-06-08 4 views

Antwort

27

Was Sie hier machen, das Standard Standard setzt Profil (das Profil, das für jede Bean verwendet wird, wenn Sie keine @Profile Annotation angeben) als production.

Was Sie brauchen eigentlich zu tun ist der Standard aktiv Profil, das wie dies geschehen ist:

spring.profiles.active=production 
+4

Das hat funktioniert und das Argument '-DDupring.profiles.active = development' überschreibt es, was ich wollte – DarVar

3

Wenn Sie Maven verwenden würde ich so etwas tun:

Being Produktion Ihr Standardprofil:

<properties> 
    <activeProfile>production</activeProfile> 
</properties> 

Und als Beispiel für ot ihre Profile:

<profiles> 
    <!--Your default profile... selected if none specified--> 
    <profile> 
     <id>production</id> 
     <activation> 
      <activeByDefault>true</activeByDefault> 
     </activation> 
     <properties> 
      <activeProfile>production</activeProfile> 
     </properties> 
    </profile> 

    <!--Profile 2--> 
    <profile> 
     <id>development</id> 
     <properties> 
      <activeProfile>development</activeProfile> 
     </properties> 
    </profile> 

    <!--Profile 3--> 
    <profile> 
     <id>otherprofile</id> 
     <properties> 
      <activeProfile>otherprofile</activeProfile> 
     </properties> 
    </profile> 
<profiles> 

In Ihrem application.properties werden Sie einstellen:

[email protected]@ 

Diese jedes Mal funktioniert für mich, hoffe, es Ihr Problem löst.

+1

Hinweis - Profil verwenden' Maven-Paket -P {Profilname} '- z. 'Maven-Paket -Produktion' für produktionsbasiertes Profil. – Artegon

2

Diese im App.java:

public static void main(String[] args) throws UnknownHostException { 
    SpringApplication app = new SpringApplication(App.class); 
    SimpleCommandLinePropertySource source = new SimpleCommandLinePropertySource(args); 
    if (!source.containsProperty("spring.profiles.active") && 
      !System.getenv().containsKey("SPRING_PROFILES_ACTIVE")) { 

     app.setAdditionalProfiles("production"); 
    } 
    ... 
} 

Dies ist, wie es in JHipster

+0

Funktioniert für Profileinstellung in AWS Lambda programmgesteuert. Vielen Dank! –

6
getan wird

ich es auf diese Weise

System.setProperty("spring.profiles.default", "dev"); 

in den Anfängen der main(...)

3

hinzufügen --spring.profiles.active=production

Beispiel

:

java -jar file.jar --spring.profiles.active=production 
Verwandte Themen