【发布时间】:2016-12-14 19:07:41
【问题描述】:
我正在尝试访问包含构建过程信息的静态 HTML 页面,它是使用 maven war 插件生成的。但是,当我尝试访问在我的项目根目录中生成的build.html 时,什么都没有显示或无法访问。但是,当我尝试访问 src/main/webapp/static 下的任何 HTML 文件时,可以使用 URL: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 战争插件
<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(弹簧配置)
@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");
}
请提出建议。提前致谢!
【问题讨论】:
-
请出示您的 web.xml
-
谢谢。。我又添加了几个配置文件,请指教。
标签: spring spring-mvc spring-boot spring-security maven-plugin