我有一个
spring-boot应用程序.当我开始在我的intellij IDE中运行Tomcat 8.0_35我没有问题,看起来很棒.我决定部署在我的VPS上,只有
HTML渲染.我通过手动将.war文件放入webapps,在我的localhost上复制了这个问题.由于我收到所有404错误,我想我可能需要设置一个webconfig类:
@Configuration public class WebConfiguration extends WebMvcAutoConfiguration.WebMvcAutoConfigurationAdapter { private static final Logger log = Logger.getLogger(WebMvcAutoConfiguration.class); @Override public void addResourceHandlers(ResourceHandlerRegistry registry) { registry.setOrder(Ordered.HIGHEST_PRECEDENCE); registry.addResourceHandler("/css/**").addResourceLocations("/resources/css/"); registry.addResourceHandler("/image/**").addResourceLocations("/resources/image/"); registry.addResourceHandler("/images/**").addResourceLocations("/resources/images/"); registry.addResourceHandler("/javascripts/**").addResourceLocations("/resources/javascripts/"); registry.addResourceHandler("/libs/**").addResourceLocations("/resources/lib/"); } @Override public void configureDefaultServletHandling(DefaultServletHandlerConfigurer configurer) { configurer.enable(); } @Bean public DispatcherServlet dispatcherServlet(){ DispatcherServlet dispatcherServlet = new DispatcherServlet(); dispatcherServlet.setThrowExceptionIfNoHandlerFound(true); return dispatcherServlet; } @Bean public ServletContextTemplateResolver templateResolver() { ServletContextTemplateResolver resolver = new ServletContextTemplateResolver(); resolver.setPrefix("/WEB-INF/"); resolver.setSuffix(".html"); resolver.setTemplateMode("HTML5"); resolver.setOrder(1); return resolver; } }
我需要ServletContextTemplateResolver因为我使用的是spring-mobile而且我在渲染页面时遇到了问题.
我没有在tomcat上的日志中看到localhost.log和cataline.log
@SpringBootApplication public class StidhamFinancialApplication extends SpringBootServletInitializer { public static void main(String[] args) throws UnknownHostException { SpringApplication app = new SpringApplication(StidhamFinancialApplication.class); Environment env = app.run(args).getEnvironment(); System.out.println(String.format("Access URLs:\n----------------------------------------------------------\n\t" + "Local: \t\thttp://127.0.0.1:%1s\n\t" + "External: \thttp://%2s:%3s\n----------------------------------------------------------",env.getProperty("server.port"),InetAddress.getLocalHost().getHostAddress(),env.getProperty("server.port"))); } @Override protected SpringApplicationBuilder configure(SpringApplicationBuilder builder) { return builder.sources(StidhamFinancialApplication.class); } }
我的所有JS和CSS文件都可以在我的IDE中找到,所有内容似乎都配置正确.我不知道下一步该尝试什么.我一直在调试这几天没有运气.
我在https://github.com/drewjocham/financial上的git上传了它
任何建议将不胜感激.
只有日志抱怨的是一些jar文件:
org.apache.jasper.servlet.TldScanner$TldScannerCallback.scan No TLD files were found in [file:/Library/apache-tomcat-8.0.35/webapps/stidhamfinancial/WEB-INF/lib/jandex-1.1.0.Final.jar]. Consider adding the JAR to the tomcat.util.scan.StandardJarScanFilter.jarsToSkip property in CATALINA_BASE/conf/catalina.properties file.
在我的logging.properties中,我添加了以下内容:
org.apache.jasper.compiler.TldLocationsCache.level = FINE org.apache.catalina.startup.TldConfig.jarsToSkip=antlr-2.7.7.jar org.apache.catalina.startup.TldConfig.jarsToSkip=spring-boot-1.3.5.RELEASE.jar org.apache.catalina.startup.TldConfig.jarsToSkip=groovy-2.4.6.jar org.apache.catalina.startup.TldConfig.jarsToSkip=javassist-3.18.1-GA.jar org.apache.catalina.startup.TldConfig.jarsToSkip=aopalliance-1.0.jar
做了一些研究后但似乎没有用.但是我不认为这可能是个问题.
解决方法
Drew1208
我打开了这个Pull请求来解决你的问题
https://github.com/drewjocham/financial/pull/1
我添加了一些hibernate配置,以便能够运行并执行测试.并且还从资源路径中删除了“/”.
UPDATE
我发现了这个问题.
资源文件夹结构如下所示:
资源
CSS
style.css文件
图片
全队6-MED-blur.png
所以在文件style.css中,图像路径是相对于该文件而不是相对于应用程序上下文.然后你需要改变:
背景图像:网址( ‘资源/图像/ stidhamfinancial /团队-6- MED-blur.png’);
至
背景图像:网址( ‘../图像/ stidhamfinancial /团队-6- MED-blur.png’);
它将显示图像.
我也在你的回购中打开了这个PR#2.