0
`@SpringBootApplication
public class RegexApplication {
@Resource
private static Environment environment;
@Autowired
private static Environment environment;

public static void main(String[] args) {
    SpringApplication.run(RegexApplication.class, args);

    System.out.println(environment.getProperty("spring.application.name"));
}

}`

I just want to print this out so I can see what the default spring.application.name is. But I'm having a hard time understanding how to do it.

I tried @Autowired and @Resource both don't seem to work.

  • `SpringApplication.run()` returns a `ConfigurableApplicationContext`, which in turn has a method called `getEnvironment()` which can be used to read a property. But as mentioned in the duplicate, if your goal is to do something on startup, there are other methods (such as defining an `CommandLineRunner` bean). But I suggest checking out the duplicate. – g00glen00b Jan 11 '23 at 20:46

0 Answers0