1

Hello I am having troubles 'serving' resources with my web server, while some of my other resources are 'serving.' (graphs.js is loading)

In my browser console:

GET http://localhost:8080/js/app.js [HTTP/1.1 400 Bad Request 2ms]
GET http://localhost:8080/includes/header.html [HTTP/1.1 400 Bad Request 4ms]
GET http://localhost:8080/cs/bootstrap.min.css [HTTP/1.1 400 Bad Request 3ms]

But these files are located in my directory as such:

css/
    bootstrap.min.css
includes/
    header.html
js/
    app.js
    controllers/
        graphs.js

When my server starts:

2014-07-28 08:25:06.748  INFO 5260 --- [           main] .t.TomcatEmbeddedServletContainerFactory : Server initialized with port: 8080
2014-07-28 08:25:06.939  INFO 5260 --- [           main] o.apache.catalina.core.StandardService   : Starting service Tomcat
2014-07-28 08:25:06.940  INFO 5260 --- [           main] org.apache.catalina.core.StandardEngine  : Starting Servlet Engine: Apache Tomcat/7.0.52
2014-07-28 08:25:07.017  INFO 5260 --- [ost-startStop-1] o.a.c.c.C.[Tomcat].[localhost].[/]       : Initializing Spring embedded WebApplicationContext
2014-07-28 08:25:07.017  INFO 5260 --- [ost-startStop-1] o.s.web.context.ContextLoader            : Root WebApplicationContext: initialization completed in 1146 ms
2014-07-28 08:25:07.346  INFO 5260 --- [ost-startStop-1] o.s.b.c.e.ServletRegistrationBean        : Mapping servlet: 'dispatcherServlet' to [/]
**mapping**
2014-07-28 08:25:07.903  INFO 5260 --- [           main] o.s.w.s.c.a.WebMvcConfigurerAdapter      : Adding welcome page: jndi:/localhost/index.html
2014-07-28 08:25:07.905  INFO 5260 --- [           main] o.s.w.s.handler.SimpleUrlHandlerMapping  : Root mapping to handler of type [class org.springframework.web.servlet.mvc.ParameterizableViewController]
2014-07-28 08:25:07.912  INFO 5260 --- [           main] o.s.w.s.handler.SimpleUrlHandlerMapping  : Mapped URL path [/**] onto handler of type [class org.springframework.web.servlet.resource.ResourceHttpRequestHandler]
2014-07-28 08:25:07.912  INFO 5260 --- [           main] o.s.w.s.handler.SimpleUrlHandlerMapping  : Mapped URL path [/webjars/**] onto handler of type [class org.springframework.web.servlet.resource.ResourceHttpRequestHandler]
2014-07-28 08:25:08.023  INFO 5260 --- [           main] o.s.j.e.a.AnnotationMBeanExporter        : Registering beans for JMX exposure on startup
2014-07-28 08:25:08.147  INFO 5260 --- [           main] s.b.c.e.t.TomcatEmbeddedServletContainer : Tomcat started on port(s): 8080/http
2014-07-28 08:25:08.149  INFO 5260 --- [           main] c.c.i.qualifier.datacentral.Application  : Started Application in 2.556 seconds (JVM running for 2.783)

and my HTML is like:

<script type="text/javascript" src="js/app.js"></script>
<script type="text/javascript" src="js/controllers/graphs.js"></script>
<link rel="stylesheet" type="text/css" href="css/bootstrap.min.css">

1 Answer 1

2

You have not stated if you have followed instructions for packaging as a war instead of a JAR and bundling Tomcat in. This does change things a little. Either way, take a look at the documentation here: http://docs.spring.io/spring-boot/docs/current-SNAPSHOT/reference/htmlsingle/#boot-features-spring-mvc-static-content

Bascally, out of the box, you can place static content in one of the locations mentioned: /static, /public, /resources or /META-INF/resorces. As for the location of these folders, well either at the root of the servlet context or on the classpath.

You can find a very basic Tomcat application here: https://github.com/mmeany/spring-boot-web-mvc that does the job.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.