APP Web non che serve risorse statiche utilizzando Stivaletto a molla e Tomcat
-
20-12-2019 - |
Domanda
Ciao Sto avendo problemi a "servire" risorse con il mio server Web, mentre alcune delle mie altre risorse sono "servendo".(graphs.js sta caricando)
Nella mia console del browser:
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]
.
Ma questi file si trovano nella mia directory in quanto tale:
css/
bootstrap.min.css
includes/
header.html
js/
app.js
controllers/
graphs.js
.
Quando inizia il mio server:
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)
.
E il mio html è come:
<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">
. Soluzione
Non hai dichiarato se hai seguito le istruzioni per il packaging come guerra invece di un barattolo e un tomcat di raggruppamento in. Questo cambia un po '.Ad ogni modo, dai un'occhiata alla documentazione qui: http://docs.spring.io/spring-boot/docs/current-snapshot/reference/htmlsingle/#Boot-Features-Spring-mvc-static-Content .
In fondo, fuori dagli schemi, è possibile posizionare contenuti statici in una delle posizioni menzionate: / statiche, / pubbliche, / risorse o / meta-inf / risorse.Per quanto riguarda la posizione di queste cartelle, bene o alla radice del contesto del servlet o sul classpath.
Puoi trovare un'applicazione Tomcat molto semplice qui: https://github.com/mmeany / molle-boot-web-mvc che fa il lavoro.