我正在尝试访问具有构建过程信息的静态HTML页面,并使用maven war插件生成它。但是,当我尝试访问项目根目录中生成的build.html
时,没有任何内容显示或无法访问。但是,当我尝试访问src/main/webapp/static
下的任何HTML文件时,我可以使用以下网址访问:http://localhost:8180/MyProject/static/about/build.html
。
但无法通过这种方式访问,我可能正在寻找:http://localhost:8180/MyProject/build.html
。
MyProject.war中的结构
MyProject.war
META-IN
static
WEB-INF
build.html
Maven War Plugin
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-war-plugin</artifactId>
<configuration>
<webResources>
<resource>
<directory>src/main/webapp/static/about</directory>
<filtering>true</filtering>
</resource>
</webResources>
<failOnMissingWebXml>false</failOnMissingWebXml>
<archive>
<manifest>
<addClasspath>true</addClasspath>
</manifest>
</archive>
</configuration>
</plugin>
WebConfiguration类(web.xml)
public class AppWebInitializer extends AbstractAnnotationConfigDispatcherServletInitializer {
@Override
protected Class<?>[] getRootConfigClasses() {
return new Class[] { AppWebConfiguration.class };
}
@Override
protected Class<?>[] getServletConfigClasses() {
return null;
}
@Override
protected String[] getServletMappings() {
return new String[] { "/" };
}
}
AppWebConfiguration(Spring配置)
@Configuration
@EnableWebMvc
@ComponentScan(basePackages = "com.mypackages")
public class AppWebConfiguration extends WebMvcConfigurerAdapter {
@Override
public void addResourceHandlers(ResourceHandlerRegistry registry) {
registry.addResourceHandler("/static/**").addResourceLocations("/static/");
}
@Bean
public ViewResolver viewResolver() {
InternalResourceViewResolver viewResolver = new InternalResourceViewResolver();
viewResolver.setViewClass(JstlView.class);
viewResolver.setPrefix("/WEB-INF/views/");
viewResolver.setSuffix(".jsp");
return viewResolver;
}
}
Spring安全配置
@Override
protected void configure(HttpSecurity http) throws Exception {
http
.authorizeRequests()
.antMatchers("/login").anonymous()
.antMatchers("/", "/home").hasRole(ADMIN)
.antMatchers("/admin/**").hasRole(ADMIN)
.and().formLogin().loginPage("/login")
.usernameParameter("ssoId").passwordParameter("password")
.and().csrf()
.and().exceptionHandling().accessDeniedPage("/errorpage");
}
请建议。提前谢谢!
答案 0 :(得分:0)
registry.addResourceHandler("/static/**").addResourceLocations("/static/");
registry.addResourceHandler("/*.html").addResourceLocations("/WEB-INF/");