How do I setup my Spring application to use hosts / domains correctly?
I am fairly new to Spring so hopefully I am describing my setup adequately to you.
My Spring setup has Tomcat built in via the configuration file WEB-INF/web.xml
and WEB-INF/mvc-dispatcher-servlet.xml
and it autogenerates / listens on localhost:8080/spring-ng-seed
(the name of the project for now).
If I put into my /etc/host
file:
127.0.0.1 spring-ng-seed.dev
127.0.0.1 api.spring-ng-seed.dev
then I still have to type into my browser spring-ng-seed.dev:8080/spring-ng-seed/index.html
How can I loose the port number and the app name prefix before index.html? (:8080/spring-ng-seed
)
Also, is it possible to have my API only respond on api.spring-ng-seed.dev
and not on spring-ng-seed.dev
? i.e have:
1) spring-ng-seed.dev
only serve the NG app
2) api.spring-ng-seed.dev
only serve the API
My WEB-INF/mvc-dispatcher-servlet.xml
file:
<?xml version="1.0" encoding="UTF-8"?>
<beans
xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:mvc="http://www.springframework.org/schema/mvc"
xmlns:security="http://www.springframework.org/schema/security"
xmlns:context="http://www.springframework.org/schema/context"
xsi:schemaLocation="
http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans.xsd
http://www.springframework.org/schema/mvc
http://www.springframework.org/schema/mvc/spring-mvc.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context.xsd
http://www.springframework.org/schema/security
http://www.springframework.org/schema/security/spring-security.xsd
"
>
<context:component-scan base-package="seed.rest.api"/>
<mvc:resources mapping="/**" location="/app/build/"/>
<mvc:annotation-driven/>
<security:global-method-security pre-post-annotations="enabled">
<security:protect-pointcut expression="execution(* seed.rest.api.*.*.**(..))"
access="ROLE_DUMMY"/>
</security:global-method-security>
</beans>
My WEB-INF/web.xml
file
<?xml version="1.0" encoding="UTF-8"?>
<web-app
xmlns="http://java.sun.com/xml/ns/javaee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="
http://java.sun.com/xml/ns/javaee
http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd
"
version="3.0"
>
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>classpath:spring/business-config.xml</param-value>
</context-param>
<listener>
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>
<servlet>
<servlet-name>mvc-dispatcher</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>mvc-dispatcher</servlet-name>
<url-pattern>/</url-pattern>
</servlet-mapping>
</web-app>
If there is any other configurations that you need from my project ill happily post them.
Thank you for your time.