2016-04-10 14 views
2

私はSpringでangularjsアプリケーションを開発中です。spring web developement - 静的コンテンツのキャッシングを無効にする

私は頻繁に自分のhtml/javascriptファイルを変更する必要があり、私は春に静的コンテンツをキャッシュしていることに気付きました。どうすればそれを無効にできますか?私はすでに...

@Configuration 
@AutoConfigureAfter(DispatcherServletAutoConfiguration.class) 
class WebMvcConfig extends WebMvcAutoConfiguration.WebMvcAutoConfigurationAdapter { 

    @Autowired 
    private Environment env; 

    @Bean 
    public ResourceUrlEncodingFilter resourceUrlEncodingFilter() { 
     return new ResourceUrlEncodingFilter(); 
    } 

    @Override 
    public void addResourceHandlers(ResourceHandlerRegistry registry) { 
     boolean devMode = this.env.acceptsProfiles("dev"); 
     //boolean useResourceCache = !devMode; 
     boolean useResourceCache = false; 
     Integer cachePeriod = devMode ? 0 : null; 

     registry.addResourceHandler("/public/**") 
       .addResourceLocations("/public/", "classpath:/public/") 
       .setCachePeriod(cachePeriod) 
       .resourceChain(useResourceCache) 
       .addResolver(new GzipResourceResolver()) 
       .addResolver(new VersionResourceResolver().addContentVersionStrategy("/**")) 
       .addTransformer(new AppCacheManifestTransformer()); 
    } 

} 

て、それを、これを試してみました

...

WebContentInterceptor webContentInterceptor; 
public @Bean WebContentInterceptor webContentInterceptor() { 
    if (this.webContentInterceptor == null) { 
     this.webContentInterceptor = new WebContentInterceptor(); 

     this.webContentInterceptor.setAlwaysUseFullPath (true); 
     this.webContentInterceptor.setCacheSeconds (0); 


     this.webContentInterceptor.setCacheMappings (new Properties() { 
      private static final long serialVersionUID = 1L; 

      { 
       put ("/styles/**", "0"); 
       put ("/scripts/**", "0"); 
       put ("/images/**", "0"); 
       put ("/js/**", "0"); 
      } 
     }); 
    } 

    return this.webContentInterceptor; 
} 

これは私のbuild.gradleファイルです

group 'xyz' 
version '1.0-SNAPSHOT' 
buildscript{ 
    repositories{ 
     mavenCentral() 
    } 
    dependencies{ 
     classpath("org.springframework.boot:spring-boot-gradle-plugin:1.3.2.RELEASE") 
    } 
} 

apply plugin: 'java' 
apply plugin: 'eclipse' 
apply plugin: 'idea' 
apply plugin: 'spring-boot' 

sourceCompatibility = 1.8 
targetCompatibility = 1.8 

repositories { 
    mavenCentral() 
    maven { url "https://repository.jboss.org/nexus/content/repositories/releases" } 
} 

dependencies { 
    compile 'org.springframework.boot:spring-boot-starter-web' 
    compile 'org.springframework.security:spring-security-web:4.0.3.RELEASE' 
    compile 'net.sf.dozer:dozer:5.4.0' 

    compile 'org.springframework.boot:spring-boot-starter-data-jpa' 
    compile 'com.h2database:h2'// For Testing purpose 
    compile 'com.google.guava:guava:19.0' // google library for data collections 

    testCompile("junit:junit") 
    //testCompile group: 'junit', name: 'junit', version: '4.11' 
} 

task wrapper(type: Wrapper){ 
    gradleVersion = '2.3' 
} 

configurations.all { 
    // https://stackoverflow.com/questions/14024756/slf4j-class-path-contains-multiple-slf4j-bindings/25694764#25694764 
    exclude module: 'slf4j-log4j12' 
} 

答えて

0

愚かな間違いでした。私はHTML/CSS/JSソースファイルを編集していましたが、コンパイルされ展開されたバージョンはこの変更の影響を受けませんでした。

3

だけに、この設定オプションを置きますあなたのapplication.properties:

spring.resources.chain.cache=false # Disable caching in the Resource chain. 

Static content served by Spring Bootに関する細かい設定オプション(# SPRING RESOURCES HANDLINGまでスクロールしてください)を参照してください。

また、Springブートによって処理されないインフラストラクチャによってキャッシュされた静的リソースとそのコンテナ(Webブラウザなど)が存在する可能性があります。このタイプのキャッシングを克服するには、cache bustingというテクニックを使用するオプションがあります。詳細については、this section of Spring Boot docsをお読みください。

+0

何とか私のために働かない。私も 'spring-boot-devtools'を起動しましたが、それは私を助けませんでした。シークレットモードでChromeを使用していますが、すべてがローカルホストであるため、インフラストラクチャの問題ではありません。しかし、それは私のマックでキャッシュがすべてのサーバーの再起動後に更新されることを知っているinteresstingですが、私のWindowsマシンでは、それは約キャッシュします。 24時間。 ...同じアプリケーション – robie2011

関連する問題