我正在使用spring boot开发一个应用程序,但是它没有使用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)
我在点击ping服务时收到以上错误消息。
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>
Spring-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 "Works still fails!!!", template might not exist or might not be accessible by any of the configured Template Resolvers</div></body></html>
任何人都可以帮我解决这个问题吗?任何线索都会有所帮助。
控制器 -
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>
答案 0 :(得分:3)
很抱歉,您的申请表格完全混乱。
你正在使用spring-boot,最好的一点是你可以摆脱XML配置,但是你混合了web.xml
无论如何你的错误都很容易,你要回复一个视图名称“作品仍然失败!!!”这与任何html模板都不匹配。
我的建议,看看一些基本的spring-boot教程,然后再从头开始
试试这个: