복붙노트

[SPRING] jar에서 실행할 때 Spring 부트가 "TemplateInputException : 템플릿을 오류 해결 중"이라고 표시합니다.

SPRING

jar에서 실행할 때 Spring 부트가 "TemplateInputException : 템플릿을 오류 해결 중"이라고 표시합니다.

IntelliJ 내에서 또는 gradle bootRun을 통해 시작할 때 완벽하게 작동하는 앱이 있습니다.

그러나, 내가 gradle bootRepackage를 수행 한 다음 결과 jar을 실행하려고하면 결국 다음과 같이됩니다.

2014-12-02 21:46:14.086 ERROR 9839 --- [nio-2014-exec-2] org.thymeleaf.TemplateEngine             : [THYMELEAF][http-nio-2014-exec-2] Exception processing template "/login": Error resolving template "/login", template might not exist or might not be accessible by any of the configured Template Resolvers
2014-12-02 21:46:14.087 ERROR 9839 --- [nio-2014-exec-2] o.a.c.c.C.[.[.[/].[dispatcherServlet]    : Servlet.service() for servlet [dispatcherServlet] in context with path [] threw exception [Request processing failed; nested exception is org.thymeleaf.exceptions.TemplateInputException: Error resolving template "/login", template might not exist or might not be accessible by any of the configured Template Resolvers] with root cause

org.thymeleaf.exceptions.TemplateInputException: Error resolving template "/login", template might not exist or might not be accessible by any of the configured Template Resolvers
    at org.thymeleaf.TemplateRepository.getTemplate(TemplateRepository.java:245)
    at org.thymeleaf.TemplateEngine.process(TemplateEngine.java:1104)
    at org.thymeleaf.TemplateEngine.process(TemplateEngine.java:1060)
    at org.thymeleaf.TemplateEngine.process(TemplateEngine.java:1011)
    at org.thymeleaf.spring4.view.ThymeleafView.renderFragment(ThymeleafView.java:335)

jar 파일에는 / templates / **가 들어 있습니다. 내용은 나에게 잘 보입니다.

하나의 가능한 (?) 요소는 레이아웃을 참조하는 html 페이지를 사용하는 것일 수 있습니다.

  layout:decorator="layouts/main"

파일이 항아리에 있는지 확인할 수 있습니다.

/ 로그인은 다음과 같이 정의됩니다.

@Override
public void addViewControllers(ViewControllerRegistry registry) {
    registry.addViewController("/login").setViewName("/login");
    registry.addViewController("/").setViewName("/login");
}

스프링 보안은 다음과 같이 구성되어 있습니다.

@Configuration
public class WebSecurityConfig extends WebSecurityConfigurerAdapter {

@Override
public void configure(WebSecurity security) {
    security.ignoring().antMatchers("/assets/**");
}

@Override
protected void configure(HttpSecurity http) throws Exception {
    http
            .csrf().disable();
    http
            .authorizeRequests()
            .antMatchers("/").permitAll()
            .anyRequest().authenticated();
    http
            .formLogin()
            .loginPage("/login")
            .defaultSuccessUrl("/home")
            .failureUrl("/login?error")
            .permitAll()
            .and()
            .logout()
            .invalidateHttpSession(true)
            .logoutSuccessUrl("/login?logout")
            .permitAll();
}
}

나는 그것이이 이슈와 관련이있을 것이라고 생각합니다 ...

나는 https://github.com/spring-projects/spring-boot/issues/112와 Spring을위한 Thymeleaf 뷰의 적절한 위치를 보았다. 이러한 리소스에도 불구하고 템플릿 해결 작업에 성공하지 못했습니다.

모든 제안을 감사하게 받았습니다.

Spring Boot로 지금까지 왔으므로 마지막 장애물 (거의 최종적인 배치)을 우연히 만난 것은 당황 스럽습니다.

해결법

  1. ==============================

    1.나는 기본 설정에 의해 thymeleaf와 함께 봄 부팅을 사용하는 것과 같은 문제가 있었다. 내가 시도해야 할 때까지 모두 일했다.

    나는 기본 설정에 의해 thymeleaf와 함께 봄 부팅을 사용하는 것과 같은 문제가 있었다. 내가 시도해야 할 때까지 모두 일했다.

    메시지 : ... org.thymeleaf.exceptions.TemplateInputException : "/ fragments / footer"템플릿을 해석하는 중 오류가 발생했습니다.

    나는 /와 놀기를 해결했지만 문제는 슬래시가 필요 없다는 것이 었습니다.

    나는 이것을 바꿨다 :

    <footer class="footers" th:replace="/fragments/footer :: footer">
    

    이것을 위해 :

    <footer class="footers" th:replace="fragments/footer :: footer">
    
  2. ==============================

    2.대답은 여기에있는 것 같습니다 : https://github.com/spring-projects/spring-boot/issues/1744

    대답은 여기에있는 것 같습니다 : https://github.com/spring-projects/spring-boot/issues/1744

    간단히 말해서 : 리소스 경로에 '//'가 포함되면 일이 잘못됩니다.

    해결 방법은 application.yml을 수정하는 것입니다.

    spring:
      thymeleaf:
        prefix: classpath:/templates
    

    (수정 사항은 .properties 파일과 유사합니다.)

    노크 - 온 효과는 (Thymeleaf .html 파일에서와 같이) 템플리트 또는 슬래시 앞에 있어야하는 모든 참조입니다.

          layout:decorator="/layouts/main"
    

    또는 (Groovy 컨트롤러) :

    @RequestMapping(value = "/home", method = RequestMethod.GET)
    def home(Model model, Principal principal) {
    
        "/home/home"
    }
    

    나는 봄 부츠가 이것을 고쳐야한다고 생각한다. 긴급하게. 이것은 마치 최종 배포가 가까워지고있는 것처럼 느껴지는 지점에서 심하게 날아 오르는 나쁜 인체 공학입니다.

  3. ==============================

    3.알았어, 네가 가까이서 봐야 할 곳을 찾았 어. Controller 클래스에서 @RequestMapping을 클래스에 사용하면 선행 슬래시 (예 : @RequestMapping ( "property"))가 발생하지 않습니다. On Method에서는 선행 슬래시 (예 : @GetMapping ( "/ list"))가 필요하며 반환 값에는 슬래시가 없습니다 (예 : 'property / list'반환).

    알았어, 네가 가까이서 봐야 할 곳을 찾았 어. Controller 클래스에서 @RequestMapping을 클래스에 사용하면 선행 슬래시 (예 : @RequestMapping ( "property"))가 발생하지 않습니다. On Method에서는 선행 슬래시 (예 : @GetMapping ( "/ list"))가 필요하며 반환 값에는 슬래시가 없습니다 (예 : 'property / list'반환).

    예제 스 니펫

    @Controller
    @RequestMapping("property")
    public class PropertyController {
        @NonNull PropertyService service;
    
        @GetMapping("/list")
        public String list() {
            return "property/list";
        }
    }
    
  4. ==============================

    4.spring.thymeleaf.prefix = classpath : / templates /

    spring.thymeleaf.prefix = classpath : / templates /

    변화

    @Override
    public void addViewControllers(ViewControllerRegistry registry) {
        registry.addViewController("/login").setViewName("/login");
        registry.addViewController("/").setViewName("/login");
    }
    

    @Override
    public void addViewControllers(ViewControllerRegistry registry) {
        registry.addViewController("/login").setViewName("login");
        registry.addViewController("/").setViewName("login");
    }
    

    뷰 이름은 상대 경로 여야합니다.

  5. ==============================

    5.많은 조만간 템플릿 오류에 대한 내 문제를 해결할 방법을 찾았습니다. 나는 spring-boot의 새 버전과 관련이 있는지 알지 못한다. 그러나 나의 변화가 효과가있다.

    많은 조만간 템플릿 오류에 대한 내 문제를 해결할 방법을 찾았습니다. 나는 spring-boot의 새 버전과 관련이 있는지 알지 못한다. 그러나 나의 변화가 효과가있다.

    예를 들어 문자열 "/ login"을 반환하는 대신 컨트롤러를 통해 요청할 때마다 ModelAndView 객체를 만들도록 변경합니다.

    @RequestMapping(value="/login", method=RequestMethod.GET)
    public ModelAndView login() {
        ModelAndView mv = new ModelAndView("login");
        return mv;
    }
    

    모두에게 안아 준다.

  6. ==============================

    6.나는 spring-boot-startter-thymeleaf 의존성을 사용할 때이 문제에 직면했다.

    나는 spring-boot-startter-thymeleaf 의존성을 사용할 때이 문제에 직면했다.

    그래서 나는 아래의 의존성을 대신 사용했다.

            <dependency>
                <groupId>org.thymeleaf</groupId>
                <artifactId>thymeleaf</artifactId>
                <version>3.0.9.RELEASE</version>
            </dependency>
    
  7. from https://stackoverflow.com/questions/27249078/spring-boot-gives-templateinputexception-error-resolving-template-when-runnin by cc-by-sa and MIT license