2016-10-15 4 views
2

여기에서 발견 한 모든 팁과 트릭을 시도했지만 여전히 운이 없습니다. Thymeleaf와 Spring webapp를 가지고 있습니다. IDEA에서 업데이트를 호출하면 리소스와 템플릿이 다시로드되지 않습니다 (다시로드 할 필요 없음). 그런 다음 ctrl + f5를 브라우저에서 누르면 미친 듯이 변경 될 수 있습니다.스프링 부트와 Thymeleaf - 템플리트와 리소스를 다시 한 번 교환하십시오.

모든 것이 이런 식으로 하나 개의 자바 클래스로 구성되어

@EnableWebMvc 
public class MvcConfig extends WebMvcConfigurerAdapter implements ApplicationContextAware { 

내 폴더 구조는 이제 this처럼 보이지만 나는 또한 "정적"폴더없이 또는 웹 애플리케이션/자원 자원을 넣어했습니다.

ResourceHandlerRegistry : 나는 두 application.properties에서 캐시 = false를 지정

@Override 
public void addResourceHandlers(final ResourceHandlerRegistry registry) { 
    super.addResourceHandlers(registry); 
    registry.addResourceHandler("/img/**").addResourceLocations("classpath:/static/img/"); 
    registry.addResourceHandler("/css/**").addResourceLocations("classpath:/static/css/"); 
    registry.addResourceHandler("/js/**").addResourceLocations("classpath:/static/js/"); 
} 

:

spring.thymeleaf.cache=false 

및 언급 MvcConfig 클래스의

:

@Bean 
public SpringResourceTemplateResolver templateResolver() { 
    SpringResourceTemplateResolver templateResolver = new SpringResourceTemplateResolver(); 
    templateResolver.setApplicationContext(this.applicationContext); 
    templateResolver.setPrefix("/WEB-INF/templates/"); 
    templateResolver.setSuffix(".html"); 
    templateResolver.setTemplateMode(TemplateMode.HTML); 
    templateResolver.setCacheable(false); 
    return templateResolver; 
} 

는 SO에 대한 몇 가지 답변에 따르면, devtools에 대한 의존성을 추가했습니다 :

<dependency> 
    <groupId>org.springframework.boot</groupId> 
    <artifactId>spring-boot-devtools</artifactId> 
    <version>1.4.1.RELEASE</version> 
    <optional>true</optional> 
</dependency> 

여전히 작동하지 않습니다. 일부는 사실 addResources =으로 받는다는 부팅 플러그인을 추가했다, 그래서 내가 그랬어 : 나는 업데이 트를 호출 할 때, 내 자바 클래스가 즉시 다시로드되기 때문에

<plugin> 
    <groupId>org.springframework.boot</groupId> 
    <artifactId>spring-boot-maven-plugin</artifactId> 
    <version>1.4.1.RELEASE</version> 
    <configuration> 
     <addResources>true</addResources> 
    </configuration> 
</plugin> 

내 아이디어는 것 같아요 제대로 설정되어 있습니다. 리소스와 html 파일 만이 아닙니다. 서버를 다시 시작해야합니다. 실제 * .html 파일은 그다지 큰 거래는 아니지만 모든 작은 CSS 및 js 변경이 끝나면 서버를 다시 시작하는 데 많은 어려움이 있습니다. 그리고 무엇이 잘못되었는지 대략 15 시간을 잃어 버렸기 때문에 정말 실망 스럽습니다.

도움이 될 것입니다.

+0

방금 ​​알아 낸 것은 변경 사항입니다. 실제로 "대상"폴더에는 반영되지만 실행중인 앱에는 반영되지 않습니다. – Luke

+0

이 하나가 나를 위해 속임수를했다 http://stackoverflow.com/questions/21399586/hot-swapping-in-spring-boot/43114954#43114954 – shabby

답변

0

그래, 내 구체적인 경우에 대한 답변을 찾았습니다. 문제는 내 앱에서나 전혀 그렇지 않다 (아마도 .. 아마). Tomcat 8.5.5 대신 Tomcat 7으로 다시 전환했습니다. 모든 것이 이제는 제대로 작동합니다. 왜 누군가는 그 이유를 알고 있습니까?

2

나는 그것에 대해 약간의 시간을 보냈다. 그리고 마침내 내가 어떻게 작동하는지 설명 할 것이다. 주변 인터넷 검색 몇 가지 정보를 찾을 수 있습니다 것은 :

봄 부팅 application.properties : SO - Netbeans 8 won't reload static Thymeleaf files

내 inital 접근

  • Spring Boot hot swap
  • SO - Spring Boot + Jetty & hot deployment
  • 캐싱을 비활성화하고 봄 dev에 도구를 추가하는 것이 었습니다

    spring.thymeleaf.cache=false 
    spring.thymeleaf.mode=LEGACYHTML5 
    spring.thymeleaf.prefix=/templates/ 
    

    pom.프로젝트 (인 IntelliJ 아이디어에서 CTRL + F9)를 만드는 경우에만 핫스왑이 이루어지기 때문에 위의 코드 조각을 사용하여 XML은

    <dependency> 
         <groupId>org.springframework.boot</groupId> 
         <artifactId>spring-boot-devtools</artifactId> 
         <optional>true</optional> 
        </dependency> 
    

    충분하지 않습니다. 이는 기본 템플릿 확인자가을 기반으로하는 클래스 경로이며 재 컴파일이 필요한 이유 때문입니다.

    application.properties

    spring.thymeleaf.cache=false 
    spring.thymeleaf.mode=LEGACYHTML5 
    spring.thymeleaf.templates_root=src/main/resources/templates/ 
    

    Application 클래스 I 찾을

    @SpringBootApplication 
    public class MyApplication { 
    
        @Autowired 
        private ThymeleafProperties properties; 
    
        @Value("${spring.thymeleaf.templates_root:}") 
        private String templatesRoot; 
    
        public static void main(String[] args) { 
         SpringApplication.run(MyApplication.class, args); 
        } 
    
        @Bean 
        public ITemplateResolver defaultTemplateResolver() { 
         FileTemplateResolver resolver = new FileTemplateResolver(); 
         resolver.setSuffix(properties.getSuffix()); 
         resolver.setPrefix(templatesRoot); 
         resolver.setTemplateMode(properties.getMode()); 
         resolver.setCacheable(properties.isCache()); 
         return resolver; 
        } 
    } 
    

    :


    작업 솔루션 파일 시스템을 기반으로 해결 프로그램을 사용하여 defaultTemplateResolver을 무시하는 것입니다 이 해결책 opti 당신이 구성을 외부화하고 다른 프로파일 (dev, prod 등)을 사용하면서 변경 사항을 다시 불러올 때 F5를 누르면 이 변경됩니다.