1

I have Spring boot webapp running from jar. Spring boot for some reason cannot find src/mai/webapp/index.html and returns There was an unexpected error (type=Not Found, status=404).

@Configuration
@EnableWebMvc
public class WebMvcConfig extends WebMvcConfigurerAdapter {
    @Override
    public void configureDefaultServletHandling(DefaultServletHandlerConfigurer configurer){
        configurer.enable();
    }
    @Bean
    public InternalResourceViewResolver viewResolver(){
        InternalResourceViewResolver viewResolver = new InternalResourceViewResolver();
        viewResolver.setPrefix("WEB-INF/pages");
        viewResolver.setSuffix(".jsp");
        return viewResolver;
    }

    @Override
    public void addResourceHandlers(ResourceHandlerRegistry registry) {
        registry.addResourceHandler("/**").addResourceLocations("/");
    }

}
9
  • 1
    do you have more logs ? Commented Jan 26, 2015 at 8:37
  • I am running Spring Boot from console and there is no log information. Commented Jan 26, 2015 at 8:40
  • Does it work if you don't customize the ResourceHandlerRegistry and just put the content to one of the default locations? Commented Jan 26, 2015 at 8:45
  • It works when spring-boot:run Maven goal but not in a JAR. Commented Jan 26, 2015 at 8:46
  • 1
    btw - I reckon this is probably a duplicate of: stackoverflow.com/questions/27566967/… Commented Jan 26, 2015 at 9:09

1 Answer 1

3

Solved problem by adding plugin

<plugin>
            <artifactId>maven-resources-plugin</artifactId>
            <version>2.6</version>
            <executions>
                <execution>
                    <id>copy-resources</id>
                    <phase>validate</phase>
                    <goals>
                        <goal>copy-resources</goal>
                    </goals>
                    <configuration>
                        <outputDirectory>${basedir}/target/classes/static</outputDirectory>
                        <resources>
                            <resource>
                                <directory>src/main/webapp</directory>
                                <filtering>true</filtering>
                            </resource>
                        </resources>
                    </configuration>
                </execution>
            </executions>
        </plugin>
        <plugin>
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.