Create an account

Very important

  • To access the important data of the forums, you must be active in each forum and especially in the leaks and database leaks section, send data and after sending the data and activity, data and important content will be opened and visible for you.
  • You will only see chat messages from people who are at or below your level.
  • More than 500,000 database leaks and millions of account leaks are waiting for you, so access and view with more activity.
  • Many important data are inactive and inaccessible for you, so open them with activity. (This will be done automatically)


Thread Rating:
  • 162 Vote(s) - 3.4 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Setting the default active profile in Spring-boot

#11
We to faced similar issue while setting `spring.profiles.active` in java.

This is what we figured out in the end, after trying four different ways of providing `spring.profiles.active`.

In `java-8`
```
$ java --spring.profiles.active=dev -jar my-service.jar
Gives unrecognized --spring.profiles.active option.
```
```
$ java -jar my-service.jar --spring.profiles.active=dev
# This works fine
```
```
$ java -Dspring.profiles.active=dev -jar my-service.jar
# This works fine
```
```
$ java -jar my-service.jar -Dspring.profiles.active=dev
# This doesn't works
```

In `java-11`
```
$ java --spring.profiles.active=dev -jar my-service.jar
Gives unrecognized --spring.profiles.active option.
```
```
$ java -jar my-service.jar --spring.profiles.active=dev
# This doesn't works
```
```
$ java -Dspring.profiles.active=dev -jar my-service.jar
# This works fine
```
```
$ java -jar my-service.jar -Dspring.profiles.active=dev
# This doesn't works
```


**NOTE:** If you're specifying `spring.profiles.active` in your `application.properties` file then make sure you provide `spring.config.location` or `spring.config.additional-location` option to java accordingly as mentioned above.
Reply

#12
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
Reply

#13
you can also have multiple listings in the @Profile annotation

@Profile({"dev","default"})

If you set "default" as an additional value, you don't have to specify spring.profiles.active
Reply

#14
The neat way to do this without changing your source code each time is to use the OS environment variable `SPRING_PROFILES_ACTIVE`:

```sh
export SPRING_PROFILES_ACTIVE=production
```

[how-to-set-active-spring-profiles][1]

[1]:

[To see links please register here]

Reply

#15
Try this:
`@PropertySource("classpath:${spring.profiles.active:production}_file.properties")`
Reply

#16
If you are using **application.yml** for your config then add this to it, to set the default active profile:

```
spring:
profiles:
active: production
```
Reply

#17
If anyone out there trying to load profile-specific properties for spring web(not boot)
Then do this, can add multiple profiles to pom. Then in config class we can read the build profile and load props accordingly

> build like mvn clean install -Pdev

pom.xml

<profiles>
<profile>
<id>prod</id>
<properties>
<activatedProperties>prod</activatedProperties>
</properties>
<activation>
<!-- activate if system properties 'env=prod' -->
</activation>
<build><finalName>Finger</finalName></build>
</profile>
</profiles>

class

@Configuration
@PropertySource({"classpath:application.properties"})
public class MyApplicationConfiguration {
@Bean
public static PropertySourcesPlaceholderConfigurer propertySourcesPlaceholderConfigurer() {

PropertySourcesPlaceholderConfigurer configurer = new PropertySourcesPlaceholderConfigurer();
Resource resource = new ClassPathResource("/application.properties");
try {
Properties props1 = PropertiesLoaderUtils.loadProperties(resource);
resource = new ClassPathResource("/application-"+props1.getProperty("spring.profiles.active")+".properties");
configurer.setProperties(props1);
configurer.setLocation(resource);
} catch (IOException e) {
e.printStackTrace();
}
return configurer;
}
}

Reply



Forum Jump:


Users browsing this thread:
1 Guest(s)

©0Day  2016 - 2023 | All Rights Reserved.  Made with    for the community. Connected through