How to check if my spring application is in production environment?

Asked

Viewed 672 times

3

when it is in production I want that when it falls into an exception send an email to the support but only in production , in development I do not want it to perform this task .

  • You can create a property in a configuration file and make the code look at this property to know what environment it is running in.

  • I found the problem solving prop spring-boot has a native class called Environment so inject it :)

1 answer

4


The solution was to inject a spring boot class called Environment .

@Autowired
private Environment environment;

environment.getActiveProfiles()[0].equals("production"));

Application file.properties

#ENVIRONMENT
spring.profiles.active=develop

Browser other questions tagged

You are not signed in. Login or sign up in order to post.