2

I have shell script which is simply building and deploying my spring boot app.

Within this script I have only 1 command:

mvn spring-boot:run

Is it possible to print URL under which my app was deployed after deployment is successfully finished? The best would be if I can obtain this URL somehow and print it on the console.

EDIT I used following solution

@Component
public class ListenerContainer {

    @Autowired
    Environment environment;

    private Logger logger = LoggerFactory.getLogger(ListenerContainer.class);

    @EventListener(ApplicationReadyEvent.class)
    public void postStartupPrint() throws UnknownHostException {
        logger.info("Application deployed under: http://"
                + InetAddress.getLocalHost().getHostAddress()
                + ":"
                + environment.getProperty("local.server.port"));
    }
}
piechos
  • 123
  • 2
  • 10
  • You can try "[Launch browser automatically after spring-boot webapp is ready](https://stackoverflow.com/questions/27378292/launch-browser-automatically-after-spring-boot-webapp-is-ready)", pass your hostname depending on environment & some endpoint you wish. – buræquete Nov 03 '18 at 12:20
  • I don't want to launch browser. I need this url on the console. – piechos Nov 03 '18 at 12:24

1 Answers1

0

You can log the url after your context is ready, which can be seen during mvn spring-boot:run

@Component
public class ListenerContainer {

    // autowire & get logic for hostname & context path

    @EventListener(ApplicationReadyEvent.class)
    public void postStartupPrint() {
        System.out.println(hostname + contextPath + "/actuator/health");
    }
}

where hostname can be gathered from here, and contextPath from here

This is just an idea, I have no environment to test, hope it would help!

More on Spring Events

buræquete
  • 14,226
  • 4
  • 44
  • 89