Ich entwickle eine angularjs Anwendung mit Spring.spring web development - Caching für statischen Inhalt deaktivieren
Ich muss oft meine html/javascript Datei ändern und ich habe bemerkt, dass spring statischen Inhalt zwischenspeichert. Wie kann ich das deaktivieren?
ich dies schon versucht ...
@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());
}
}
und ...
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;
}
das ist mein build.gradle Datei
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'
}
es funktioniert irgendwie nicht für mich. Ich habe auch 'Spring-Boot-Devtools' aktiviert, aber es hat mir nicht geholfen. Ich verwende Chrome im Inkognito-Modus und alles ist localhost, also sollte es kein Infrastrukturproblem sein. Aber es ist interessant zu wissen, dass auf meinem Mac der Cache nach jedem Neustart des Servers aktualisiert wird, aber auf meinem Windows-Rechner zwischengespeichert wird. 24 Stunden. ... dieselbe Anwendung – robie2011