Skip to content

Instantly share code, notes, and snippets.

@rbaul
Created January 3, 2019 12:44
Show Gist options
  • Save rbaul/4dacb0274e25e5bdbf959703fe0943e2 to your computer and use it in GitHub Desktop.
Save rbaul/4dacb0274e25e5bdbf959703fe0943e2 to your computer and use it in GitHub Desktop.
Spring Application get server context path
server:
context-path: /my-context // Caused by: java.lang.IllegalArgumentException: ContextPath must start with '/' and not end with '/'
port: 8080
@Slf4j
@Component
public class AppStartupRunner implements ApplicationRunner {
@Autowired
private ServletContext servletContext;
@Override
public void run(ApplicationArguments args) throws Exception {
log.info(">>>>>>> Context Path is : {}", servletContext.getContextPath()); // Result: "/my-context"
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment