I want my default active profile to be production
if -Dspring.profiles.active
is not set.
I tried the following in my application.pro
If you are using AWS Lambda with SprintBoot, then you must declare the following under environment variables:
key: JAVA_TOOL_OPTIONS & value: -Dspring.profiles.active=dev
add --spring.profiles.active=production
Example:
java -jar file.jar --spring.profiles.active=production
I do it this way
System.setProperty("spring.profiles.default", "dev");
in the very beginning of main(...)
If you're using maven I would do something like this:
Being production your default profile:
<properties>
<activeProfile>production</activeProfile>
</properties>
And as an example of other profiles:
<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 your application.properties you'll have to set:
spring.profiles.active=@activeProfile@
This works for me every time, hope it solves your problem.
Try this:
@PropertySource("classpath:${spring.profiles.active:production}_file.properties")
In AWS LAMBDA:
For $ sam local
you add the following line in your sam template yml file:
Resources:
FunctionName:
Properties:
Environment:
Variables:
SPRING_PROFILES_ACTIVE: local
But in AWS Console: in your Lambda Environment variables just add:
KEY:JAVA_TOOL_OPTIONS
VALUE:-Dspring.profiles.active=dev