programing

스프링 부츠는 "템플릿"을 제공합니다.입력 예외:jar에서 실행할 때 "템플릿 확인 중 오류 발생"

css3 2023. 7. 19. 21:31

스프링 부츠는 "템플릿"을 제공합니다.입력 예외:jar에서 실행할 때 "템플릿 확인 중 오류 발생"

저는 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)

저는 병에 /templates/**가 들어있는 것을 볼 수 있습니다. 그 내용물은 제가 보기에 괜찮아 보입니다.

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

  layout:decorator="layouts/main"

나는 파일이 병 안에 있다는 것을 확인할 수 있습니다.

/dll은 다음과 같이 정의됩니다.

@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 과 봄을 위한 Thymeleaf 뷰의 적절한 위치를 보았습니다(다른 것들보다 더 많이).이러한 리소스에도 불구하고 템플릿 해결 작업에 성공하지 못했습니다.

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

Spring Boot와 함께 아직 마지막 장애물(최종 배치에 가까운)에 걸려 넘어지지 않은 것은 성가신 일입니다.

기본적으로 스프링 부트를 백리프와 함께 사용할 때도 동일한 문제가 있었습니다.제가 .jar를 시도해야 할 때까지 모두 작동했습니다.

메시지에 따르면... 오르간.티메리프.예외 사항템플릿입력 예외:템플릿 "/fragments/footer" 확인 중 오류 발생

저는 /, 문제는 슬래시가 필요 없다는 것을 필요로 하지 않는다는 것을 해결했습니다.

변경 내용:

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

이 경우:

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

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

한마디로 리소스 경로에 '//'가 포함되어 있으면 상황이 틀어집니다.

이 문제는 application.yml을 수정하는 것입니다.

spring:
  thymeleaf:
    prefix: classpath:/templates

(물론 .properties 파일의 경우에도 마찬가지입니다.)

(Thymeleaf.html 파일)에서와 같이 템플릿 또는 필요한 모든 참조 앞에 슬래시가 있어야 합니다.

      layout:decorator="/layouts/main"

또는 (그루비 컨트롤러):

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

    "/home/home"
}

저는 봄 부츠가 이것을 고쳐야 한다고 생각합니다.급합니다.이것은 정말 나쁜 인체공학적인 것으로, 사람들이 최종 배치에 가까워지고 있다고 느끼는 바로 그 시점에서 심하게 폭발합니다.

알겠습니다, 자세히 살펴봐야 할 곳을 찾았습니다.컨롤러클다서때사를 할 때@RequestMapping슬래시 ( 클에서선슬예없음래시행스래예():@RequestMapping("property")Method에서는 선행 슬래시(예:@GetMapping("/list")) 및 반환 값 선행 슬래시 없음(예:return "property/list";)

예제 조각

@Controller
@RequestMapping("property")
public class PropertyController {
    @NonNull PropertyService service;

    @GetMapping("/list")
    public String list() {
        return "property/list";
    }
}

사용할 때 문제가 발생했습니다.spring-boot-starter-thymeleaf의존

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

        <dependency>
            <groupId>org.thymeleaf</groupId>
            <artifactId>thymeleaf</artifactId>
            <version>3.0.9.RELEASE</version>
        </dependency>

만약 위의 해결책들이 나처럼 당신에게 효과가 없다면,

컨트롤러를 Rest Controller로 변경했습니다.그것이 제 문제를 해결했습니다.

이는 Angular와 같은 Front End App을 사용하여 백엔드 애플리케이션과 대화하는 경우입니다.

제 코드에는 아무런 문제가 없었습니다.내가 한 것은 단지 실행한 것입니다.mvn clean터미널에서 명령을 실행한 다음 앱을 다시 시작하면 정상적으로 작동합니다.

@RestController 주석이 @responseBody 주석과 @controller 주석이 혼합되어 있기 때문에 이 문제는 @Restcontroller 주석과 관련이 있습니다.

RestController 기본 응답 본문은 json 또는 문자열 형식입니다. html 이름이 추가될 때마다 문자열로 간주되고 기본 html의 표시 문자열로 간주됩니다.

@restController를 @controller로 변경하면 작동합니다.

봄, 너의 잎prefix=classpath:/prefix/

바꾸다

@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");
}

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

저는 많은 조언 끝에 템플릿 오류에 대한 제 문제를 해결할 방법을 찾았습니다.스프링부츠의 새로운 버전과 관련이 있는지는 모르겠지만, 제 변화는 효과가 있었습니다.

예를 들어 String "/login"을 반환하는 대신 컨트롤러를 통해 요청할 때마다 ModelAndView 개체를 생성하도록 변경합니다.

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

모두를 위한 포옹

언급URL : https://stackoverflow.com/questions/27249078/spring-boot-gives-templateinputexception-error-resolving-template-when-runnin