4

Is it possible to run static content and java related code on different ports?

I have a spring boot project where my java code resides on src/main/java and web content on src/main/resources/static.

Is there a possibility to run static content on port like 8080 and java (rest controller) on 8081 ?

I don't want to create a separate project for UI.

Bilesh Ganguly
  • 3,315
  • 3
  • 37
  • 53
Raki_2012
  • 97
  • 1
  • 7
  • Why do you want to do that? – Thilo Aug 29 '16 at 05:43
  • If it's really static content, you can run an nginx on 8080 off `src/main/resources/static` in addition to Spring Boot. – Thilo Aug 29 '16 at 05:44
  • 2
    I don't think so since they run in the same web container. But you can always create 2 Spring boot applications though it's a weird prerequisite to have them running on different ports. However, creating a Spring boot application to just serve static content seems overkill to me so you might prefer a web server like Apache HTTpd, nginx, ... . – g00glen00b Aug 29 '16 at 05:44
  • @Thilo : Thank you for response.. The reason behind this is i want to restrict people from accessing my UI and serve it as an admisntrator UI and i dont want to do a role based authorization. Just an inquisite whether it can be done ?? – Raki_2012 Aug 29 '16 at 06:20
  • why not serve static content under different path like http://server:port/context/static – kuhajeyan Aug 29 '16 at 10:01
  • @Raki_2012 so you plan to restrict people from accessing your UI by running a non secured application on a different port because people won't find out about it? You should google "security through obscurity" and why it's bad. – g00glen00b Aug 29 '16 at 11:51
  • 1
    You can have a single Spring Boot App with multiple profiles (ex: http://stackoverflow.com/questions/39205430/how-to-run-spring-boot-as-a-client-application/39206323#39206323), each launching the application using different application-${profile}.properties. However, I'm not sure I see the point, you could just as well follow @kuhajeyan 's advice and set a different context path for the static content. – alexbt Aug 31 '16 at 04:50

0 Answers0