dimanche 12 juin 2016

Unable to render images from CSS file when I manually deployed war file in Tomcat 8

This is a very strange and bug. All images in my CSS will not render when I place the war file in Tomcat 8. However everything works fine when I start the application in Tomcat with my Intellij IDE.

Naturally it must be a path issue, so for example:

ul.feature-list.feature-list-icon-small li span.icon.icon-address           { background-image:url('/resources/image/icon_feature/small/address.png');          }
ul.feature-list.feature-list-icon-small li span.icon.icon-adjust            { background-image:url('/resources/image/icon_feature/small/adjust.png');           }
ul.feature-list.feature-list-icon-small li span.icon.icon-administration    { background-image:url('/resources/image/icon_feature/small/administration.png');

These give me 404 errors when deployed to Tomcat 8. So I remove the /:

ul.feature-list.feature-list-icon-small li span.icon.icon-address           { background-image:url('resources/image/icon_feature/small/address.png');           }
ul.feature-list.feature-list-icon-small li span.icon.icon-adjust            { background-image:url('resources/image/icon_feature/small/adjust.png');            }
ul.feature-list.feature-list-icon-small li span.icon.icon-administration    { background-image:url('resources/image/icon_feature/small/administration.png');

404 error are gone but still nothing, same behavior!

I configured the application like so:

 @Configuration
    public class WebConfiguration extends WebMvcAutoConfiguration.WebMvcAutoConfigurationAdapter {

        private static final Logger LOGGER = Logger.getLogger(WebConfiguration.class);

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

        @Bean
        public HibernateJpaSessionFactoryBean sessionFactory(EntityManagerFactory emf) {
            HibernateJpaSessionFactoryBean factory = new HibernateJpaSessionFactoryBean();
            factory.setEntityManagerFactory(emf);
            return factory;
        }

        @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("/templates/**").addResourceLocations("/resources/templates/");

            registry.addResourceHandler("/libs/**").addResourceLocations("/resources/libs/");
        }

    }

I had to do this because when I brought in Spring-mobile spring-boot would not auto configure even with @EnableAutoConfiguration.

enter image description here

I unzipped my war file to confirm the file are in the right place. At this point I am not sure what to do.

Here is the application on GIT https://github.com/drewjocham/financial

This will run on the IDE, however when you run mvn clean install manually place it in Tomcat 8 and start the browser any image I put in my styles.css file will not render.

Aucun commentaire:

Enregistrer un commentaire