2017-02-21 45 views
0

Я разрабатываю приложение с пружинной загрузкой, но его неудачей с конфигурацией Thymeleaf -Spring Загрузитесь с Thymeleaf В противном случае

[THYMELEAF][http-nio-8080-exec-4] Exception processing template "Works still fails!!!": Error resolving template "Works still fails!!!", template might not exist or might not be accessible by any of the configured Template Resolvers 
Feb 21, 2017 12:37:47 PM org.apache.catalina.core.StandardWrapperValve invoke 
SEVERE: Servlet.service() for servlet [dispatcherServlet] in context with path [/ursserver] threw exception [Request processing failed; nested exception is org.thymeleaf.exceptions.TemplateInputException: Error resolving template "Works still fails!!!", 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 "Works still fails!!!", template might not exist or might not be accessible by any of the configured Template Resolvers 
    at org.thymeleaf.TemplateRepository.getTemplate(TemplateRepository.java:246) 
    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) 

Я получаю вышеуказанное сообщение об ошибке на удар услуги пинга.

SpringBoot Main Class

//import org.springframework.boot.autoconfigure.EnableAutoConfiguration; 
import org.springframework.boot.autoconfigure.SpringBootApplication; 
//import org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfiguration; 
//import org.springframework.boot.autoconfigure.orm.jpa.HibernateJpaAutoConfiguration; 
import org.springframework.boot.builder.SpringApplicationBuilder; 
import org.springframework.boot.web.client.RestTemplateBuilder; 
import org.springframework.boot.web.support.SpringBootServletInitializer; 
import org.springframework.context.annotation.Bean; 
import org.springframework.context.annotation.ComponentScan; 
import org.springframework.context.annotation.Import; 
//import org.springframework.context.annotation.Import; 
import org.springframework.context.annotation.ImportResource; 
import org.springframework.context.annotation.PropertySource; 
import org.springframework.web.client.RestTemplate; 
import org.springframework.web.servlet.config.annotation.EnableWebMvc; 
import org.springframework.web.servlet.config.annotation.WebMvcConfigurationSupport; 

import com.shc.ecom.urs.convertors.URSServiceMessageConvertor; 

//import org.springframework.context.annotation.PropertySource; 
import org.springframework.boot.Banner; 


/** 
* @author bnarula 
* 
*/ 
@SpringBootApplication 
@Import({CassandraDsConfig.class}) 
@ImportResource({"spring-urs-context.xml"/*, "cassandra-dce.xml","cassandra.xml"*/ }) 
//@Import(CassandraDsConfig.class) 
@PropertySource({ "urs-application.properties", "cassandra.properties"}) 
/*@PropertySources(value = { @PropertySource("cassandra-dce.xml"), @PropertySource("cassandra.properties"), 
     @PropertySource("cassandra.xml")})*/ 
//@EnableAutoConfiguration(exclude = {DataSourceAutoConfiguration.class, HibernateJpaAutoConfiguration.class}) 
@ComponentScan(basePackages = "com.shc.ecom") 
//@EnableWebMvc 
public class URSMainModule extends SpringBootServletInitializer { 

    @Override 
    protected SpringApplicationBuilder configure(SpringApplicationBuilder builder) { 
     return configureApplication(builder); 
    } 

    public static void main(String[] args) { 
     configureApplication(new SpringApplicationBuilder()).run(args); 
    } 

    private static SpringApplicationBuilder configureApplication(SpringApplicationBuilder builder) { 
     return builder.sources(URSMainModule.class).bannerMode(Banner.Mode.OFF); 
    } 

    /*@Bean 
    public RestTemplate restTemplate(RestTemplateBuilder builder) { 
     return builder.build(); 
    }*/ 
} 

web.xml

<!DOCTYPE web-app PUBLIC 
"-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN" 
"http://java.sun.com/dtd/web-app_2_3.dtd" > 

<web-app> 
    <display-name>Archetype Created Web Application</display-name> 
    <context-param> 
     <param-name>contextConfigLocation</param-name> 
     <param-value>classpath:application-context.xml</param-value> 
    </context-param> 

    <context-param> 
     <param-name>log4jConfigLocation</param-name> 
     <param-value>classpath:log4j.properties</param-value> 
    </context-param> 

    <listener> 
     <listener-class>org.springframework.web.util.Log4jConfigListener</listener-class> 
    </listener> 

    <listener> 
     <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class> 
    </listener> 

    <servlet> 
     <servlet-name>jersey-serlvet</servlet-name> 
     <servlet-class>com.sun.jersey.spi.spring.container.servlet.SpringServlet</servlet-class> 
     <init-param> 
      <param-name>com.sun.jersey.config.property.packages</param-name> 
      <param-value>com.shc.marketplace.ias.service.MessagingApplication</param-value> 
     </init-param> 
     <load-on-startup>1</load-on-startup> 
    </servlet> 

    <servlet-mapping> 
     <servlet-name>jersey-serlvet</servlet-name> 
     <url-pattern>/*</url-pattern> 
    </servlet-mapping> 

</web-app> 

Pom имеет под Thymeleaf вход -

<dependency> 
    <groupId>org.springframework.boot</groupId> 
    <artifactId>spring-boot-starter-thymeleaf</artifactId> 
</dependency> 

весна-context.xml имеет ниже отображение для Thmeleaf -

<bean id="templateEngine" class="org.thymeleaf.spring4.SpringTemplateEngine"> 
     <property name="templateResolver" ref="templateResolver" /> 
    </bean> 

    <bean id="templateResolver" class="org.thymeleaf.spring4.templateresolver.SpringResourceTemplateResolver"> 
     <property name="prefix" value="/WEB-INF/" /> 
     <property name="suffix" value=".html"/> 
     <property name="templateMode" value="HTML5" /> 
    </bean> 

После всего этого, когда я попал в службу, он дает мне сообщение об ошибке -

<html><body><h1>Whitelabel Error Page</h1><p>This application has no explicit mapping for /error, so you are seeing this as a fallback.</p><div id='created'>Tue Feb 21 12:39:03 IST 2017</div><div>There was an unexpected error (type=Internal Server Error, status=500).</div><div>Error resolving template &quot;Works still fails!!!&quot;, template might not exist or might not be accessible by any of the configured Template Resolvers</div></body></html> 

структуру папок для веб-инф/index.html - enter image description here

Может кто-нибудь помочь мне с вопрос? Любые выводы были бы полезны.

Controller -

import javax.ws.rs.Consumes; 
import javax.ws.rs.GET; 
import javax.ws.rs.POST; 
import javax.ws.rs.Path; 
import javax.ws.rs.Produces; 
import javax.ws.rs.PathParam; 
import javax.ws.rs.core.MediaType; 

import com.shc.ecom.urs.binder.ReservationRequest; 

import org.jboss.resteasy.annotations.providers.jaxb.json.Mapped; 
import org.jboss.resteasy.annotations.providers.jaxb.json.XmlNsMap; 
import org.springframework.web.bind.annotation.RequestMapping; 
import org.springframework.web.bind.annotation.RequestMethod; 


@RequestMapping("/inventory") 
public interface ReservationService { 

@RequestMapping(value = "/ping", method = RequestMethod.GET, produces = MediaType.TEXT_PLAIN) 
    public String testWebService(); 
} 
} 

Реализация класса -

@Component 
public class ReservationServiceImpl implements ReservationService{ 
    public String testWebService() { 
     final String METHOD_NAME = "testWebService"; 
     logger.info(" Inside " + METHOD_NAME + "Request valid"); 
     return "Works still fails!!!"; 
    } 
} 

Index.html

<!DOCTYPE html> 
<html xmlns="http://www.w3.org/1999/xhtml" 
    xmlns:th="http://www.thymeleaf.org" 
    xmlns:layout="http://www.ultraq.net.nz/thymeleaf/layout"> 
<head lang="en"> 

<title>Spring Framework Guru</title> 
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" /> 
</head> 
<body> 
    <h1>Hello</h1> 

    <h2>Fellow Spring Framework Gurus!!!</h2> 
</body> 
</html> 
+2

Глядя на исключение это выглядит как thymeleaf двигатель ищет для файла шаблона с именем " Работы все еще не удались !!! " и поэтому он терпит неудачу. Убедитесь, что вы передаете правильное имя шаблона в resolver. – mhasan

+1

Отбросьте всю вашу конфигурацию, включая 'WEB-INF', переместите' index.html' в 'src/main/resources/templates /' и верните строку '' index " '(вы возвращаете' 'Works все еще не удается !!!", когда нет '' Works still failed.html "'). – chrylis

+1

И покажите нам свой контроллер. Какое имя вида вы возвращаете? у вас есть файл src/main/resources/templates/viewname.html? –

ответ

2

Я извиняюсь, но у вас есть полный беспорядок в вашем приложении.

Вы используете пружинные ботинки, который один из лучших точек является то, что вы можете избавиться от конфигурации XML, но вы смешиваете тогда web.xml

В любом случае, ваша ошибка легко, вы возвращаете имя представления "все еще не работает !!!" который не соответствует ни одному шаблону html.

Мой совет, взглянуть на некоторые основные пружинными загрузки учебник и начать с нуля

Попробуйте это:

Spring Boot web content tutorial