Java – will The war file deployed to Tomcat 8 works normally in the IDE, but when I deploy to my VPS, I lose all JS and CSS

I have a spring boot application When I started running Tomcat 8.0 in my IntelliJ IDE_ I have no problem. It looks great I decided to deploy on my VPS with only HTML rendering I set it manually The war file is put into webapps and the problem is copied on my localhost Since I received all 404 errors, I think I may need to set a webconfig class:

@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;
    }

}

I need servletcontexttemplateresolver because I use spring mobile and I have a problem rendering the page

I didn't see localhost in the log on Tomcat Log and 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);
    }
}

All my JS and CSS files can be found in my IDE, and everything seems to be configured correctly I don't know what to try next I've been debugging and have no luck these days

I am here https://github.com/drewjocham/financial Git on uploaded it

Any suggestions would be appreciated

Only the logs complain about some jar files:

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.

In my logging Properties, I added the following:

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

After doing some research, it seems useless But I don't think it could be a problem

Solution

Drew1208

I opened this pull request to solve your problem https://github.com/drewjocham/financial/pull/1

I added some hibernate configurations to be able to run and execute tests It also removed "/. From the resource path

UPDATE

I found the problem The resource folder structure is as follows: resource CSS style CSS file picture team 6-med-blur png

So in the file style In CSS, the image path is relative to the file, not to the application context Then you need to change: background image: website ('resource / image / stidhamfinancial / team-6 - med-blur. PNG '); To background image: website ('.. / image / stidhamfinancial / team-6 - med-blur. PNG');

It will display the image

I also opened this PR #2

The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
分享
二维码
< <上一篇
下一篇>>