1

ビルドプロセスの情報を持つ静的HTMLページにアクセスしようとしています。これはmaven warプラグインを使用して生成されます。しかし、プロジェクトのルートに生成されたbuild.htmlにアクセスしようとすると、何も表示されず、アクセスできなくなります。ただし、src/main/webapp/staticの下にあるHTMLファイルにアクセスしようとすると、URL:http://localhost:8180/MyProject/static/about/build.htmlを使用してアクセスできます。プロジェクトルートから静的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; 
    } 

} 

春のセキュリティ設定

@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

web.xmlを表示してください。 – jlumietu

+0

ありがとうございます。設定ファイルをいくつか追加しました。お勧めします。 – Sam

答えて

0
registry.addResourceHandler("/static/**").addResourceLocations("/static/"); 
registry.addResourceHandler("/*.html").addResourceLocations("/WEB-INF/"); 
+0

いいえ、運がいいよ!以下の行は、ファイルがWEB-INFのregistry.addResourceHandler( "/ *。html")にある場合にのみ役立つと思います。addResourceLocations( "/ WEB-INF /");それがWEB-INFの外にあればどうですか? build.htmlはルートレベルまたはWEB-INFの外で生成されるため – Sam

+0

私の春のセキュリティはbuild.htmlにアクセスする際に問題を引き起こしていますか? – Sam

+0

はい、春のセキュリティのため、あなたは目標ディレクトリをオーバーライドしたいですか? ' yourPath egWEB-INF'、[詳細はこちら](https://maven.apache.org/plugins/maven-war-plugin/examples/adding-filtering-webresources.html#Overriding_the_default_destination_directory)を設定することができます。 – chaoluo

関連する問題