Web-App nicht statischen Ressourcen mit Spring Boot und Tomcat
Hallo, ich habe Probleme " mit " Ressourcen, die mit meinem web-server, während einige von meinen anderen Ressourcen sind 'dienen.' (graphs.js ist laden)
In meinem browser-Konsole:
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]
Aber befinden sich diese Dateien in meinem Verzeichnis als solche:
css/
bootstrap.min.css
includes/
header.html
js/
app.js
controllers/
graphs.js
Wenn mein server startet:
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)
und mein HTML ist wie:
<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">
Du musst angemeldet sein, um einen Kommentar abzugeben.
Haben Sie nicht gesagt, wenn Sie folgte den Anweisungen für die Verpackung als ein Krieg statt eine JAR und die Bündelung von Tomcat in. Dies ändert die Dinge ein wenig. Entweder Weg, werfen Sie einen Blick auf die Dokumentation hier: http://docs.spring.io/spring-boot/docs/current-SNAPSHOT/reference/htmlsingle/#boot-features-spring-mvc-static-content
Bascally, out of the box, können Sie statische Inhalte in einer von den genannten Orten: /static, /public, /Ressourcen oder /META-INF/resorces. Als die Lage dieser Ordner, sowie entweder im Stammverzeichnis des servlet-Kontext oder im classpath.
Finden Sie eine sehr grundlegende Tomcat-Anwendung hier: https://github.com/mmeany/spring-boot-web-mvc, dass der job nicht.