SpringBoot jar - 缺少webapp的资源

时间:2017-05-25 21:35:08

标签: java spring eclipse maven spring-boot

问题是我使用maven作为jar的springboot应用程序构建缺少webapp的资源。我认为我搞砸了一些东西,在谷歌搜索会议后,我仍然没有想法如何解决问题

There was an unexpected error (type=Not Found, status=404).
/WEB-INF/static/index.html

转到localhost:8080 /从jar登录。

Mvn build:

<build>
     <resources>
       <resource>
        <directory>src/main/webapp/</directory>
       </resource>
     </resources>
    <plugins>
        <plugin>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-maven-plugin</artifactId>
             <executions>
                <execution>
                  <goals>
                    <goal>repackage</goal>
                  </goals>
                </execution>
             </executions>
        </plugin>
    </plugins>
</build>

这是我的eclipse项目结构: project structure

此外,我有一个配置类

@EnableWebMvc
@Configuration
@ComponentScan({ "com.staszkox.*" })
@Import({ SecurityConfiguration.class })
public class ResourcesResolver extends WebMvcConfigurerAdapter 
{
    @Bean
    public ViewResolver getViewResolver() {
        InternalResourceViewResolver resolver = new InternalResourceViewResolver();
        resolver.setPrefix("/WEB-INF/static/");
        return resolver;
    }

    @Override
    public void configureDefaultServletHandling(DefaultServletHandlerConfigurer configurer) 
    {
        configurer.enable();
    }
}


@Controller
public class ResourcesController
{
    @RequestMapping(value = "/login", method = RequestMethod.GET)
    public String login(@RequestParam(value = "error", required = false) String error,
        @RequestParam(value = "logout", required = false) String logout) 
    {
        return "index.html";
    }
}

你有什么想法吗?我已尝试使用jar的目标文件夹中的每个资源文件夹设置,但仍然没有。如果我从eclipse运行应用程序,一切正常。

0 个答案:

没有答案