2016-11-25 7 views
3

挨拶。スプリングブートThymeleaf View Restolver on Restコントローラ

私はSpring Bootアプリケーション(v 1.4.1)を持っています。 thymeleafテンプレートで厳密ではないHTMLをサポートするために - 以前

<dependency> 
    <groupId>org.springframework.boot</groupId> 
    <artifactId>spring-boot-starter-thymeleaf</artifactId> 
</dependency> 
<dependency> 
    <groupId>net.sourceforge.nekohtml</groupId> 
    <artifactId>nekohtml</artifactId> 
    <version>1.9.22</version> 
</dependency> 

nekohtmlからThymeleafを設定します。 私はThymeleafテンプレートを電子メールのテンプレートとしてのみ使用します。このアプリは、REST APIを表しており、すべてのコントローラはjsonデータを返します。

私はThymeleafを電子メールに設定した後、Thymeleafテンプレートを探して、code 500を返すように要求しているリクエストがあります。

Thymeleafの設定(YML、これはthymeleafのためのすべての設定は、他のJAVAのコンフィグ、すべての取り扱い春ブーツです):

thymeleaf: 
    check-template-location: true 
    prefix: classpath:/templates/ 
    suffix: .html 
    mode: LEGACYHTML5 
    encoding: UTF-8 
    content-type: text/html 
    cache: true 

例コントローラとエラー:

@RequestMapping(value = "/register", method = RequestMethod.POST) 
public JsonResponse AddUser(@RequestBody @Valid User user, WebRequest request) throws SQLException { 
    String result = userService.RegisterUser(user); 
    if(result.equals("done")) { 
     try { 
      eventPublisher.publishEvent(new OnRegistrationCompleteEvent(user, request.getLocale())); 
     } catch (Exception me) { 
      return new JsonResponse("FAIL", "Unknown on event publishing: "+ me.getMessage()); 
     } 
     return new JsonResponse("OK", ""); 

    } else if(result.equals("duplicate")) { 
     return new JsonResponse("FAIL", "duplicate"); 
    } 
    return new JsonResponse("FAIL", "Unknown"); 
} 

がエラー:

2016-11-25 11:02:04.285 DEBUG 15552 --- [nio-8080-exec-1] o.s.s.w.a.i.FilterSecurityInterceptor : Authorization successful 
2016-11-25 11:02:04.285 DEBUG 15552 --- [nio-8080-exec-1] o.s.s.w.a.i.FilterSecurityInterceptor : RunAsManager did not change Authentication object 
2016-11-25 11:02:04.285 DEBUG 15552 --- [nio-8080-exec-1] o.s.security.web.FilterChainProxy  : /register reached end of additional filter chain; proceeding with original chain 
2016-11-25 11:02:04.289 DEBUG 15552 --- [nio-8080-exec-1] o.s.web.servlet.DispatcherServlet  : DispatcherServlet with name 'dispatcherServlet' processing POST request for [/api/register] 
2016-11-25 11:02:04.291 DEBUG 15552 --- [nio-8080-exec-1] s.w.s.m.m.a.RequestMappingHandlerMapping : Looking up handler method for path /register 
2016-11-25 11:02:04.294 DEBUG 15552 --- [nio-8080-exec-1] s.w.s.m.m.a.RequestMappingHandlerMapping : Returning handler method [public com.springapp.models.common.JsonResponse com.springapp.controllers.api.IndexController.AddUser(com.springapp.models.common.User,org.springframework.web.context.request.WebRequest) throws java.sql.SQLException] 
2016-11-25 11:02:04.329 DEBUG 15552 --- [nio-8080-exec-1] m.m.a.RequestResponseBodyMethodProcessor : Read [class com.springapp.models.common.User] as "application/json;charset=UTF-8" with [org.springfr[email protected]682ef707] 
2016-11-25 11:02:15.620 DEBUG 15552 --- [nio-8080-exec-1] o.s.w.servlet.view.BeanNameViewResolver : No matching bean found for view name 'register' 
2016-11-25 11:02:15.635 DEBUG 15552 --- [nio-8080-exec-1] o.s.web.servlet.DispatcherServlet  : Rendering view [[email protected]] in DispatcherServlet with name 'dispatcherServlet' 
2016-11-25 11:02:15.647 ERROR 15552 --- [nio-8080-exec-1] org.thymeleaf.TemplateEngine    : [THYMELEAF][http-nio-8080-exec-1] Exception processing template "register": Error resolving template "register", template might not exist or might not be accessible by any of the configured Template Resolvers 
2016-11-25 11:02:15.651 DEBUG 15552 --- [nio-8080-exec-1] o.s.web.servlet.DispatcherServlet  : Error rendering view [[email protected]] in DispatcherServlet with name 'dispatcherServlet' 

org.thymeleaf.exceptions.TemplateInputException: Error resolving template "register", template might not exist or might not be accessible by any of the configured Template Resolvers 
+0

接頭辞:classpath:/ templates/- 接頭辞を設定し、テンプレートを/ WEB-INF/templatesに配置します。これは、thymeleafがClassLoaderTemplateResolverを使用するように設定されている場合、JAR内のテンプレートを検索するからです。 – Zildyan

答えて

2

ごめんなさい、私の間違いでした。以前は、Spring MVCからSpring Bootに移行し、REST APIとフロントエンドに分割しました。 特にコントローラには@RestControllerと注釈が付けられていませんでした。一定。

+0

そして、私はまったく同じことをして同じように修正しました。 – pauli

関連する問題