找出所有可能的解决方案后,我将其发布出来。
几天前我的spring boot应用程序运行良好。我能够在tomcat上部署它,还可以导出war并将其部署在我的应用程序服务器上。但是突然间,它在部署时显示空白页。可能是什么原因?
在pom.xml中,我具有所有依赖项:
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0
http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.sdigital</groupId>
<artifactId>cheapTravelTicket</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>war</packaging>
<name></name>
<description>cheap Travel Ticket</description>
<!-- Default from spring boot -->
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>1.4.3.RELEASE</version>
</parent>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<java.version>1.8</java.version>
</properties>
<dependencies>
<!-- Web Application -->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<!-- Spring data jpa -->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-jpa</artifactId>
</dependency>
<!-- Spring Webservices -->
<dependency>
<groupId>org.springframework.ws</groupId>
<artifactId>spring-ws-core</artifactId>
</dependency>
<dependency>
<groupId>xml-apis</groupId>
<artifactId>xml-apis</artifactId>
<version>1.4.01</version>
</dependency>
<!-- https://mvnrepository.com/artifact/org.w3c/dom -->
<dependency>
<groupId>org.w3c</groupId>
<artifactId>dom</artifactId>
<version>2.3.0-jaxb-1.0.6</version>
</dependency>
<!-- https://mvnrepository.com/artifact/sax/sax -->
<dependency>
<groupId>sax</groupId>
<artifactId>sax</artifactId>
<version>2.0.1</version>
</dependency>
<!-- Embedded Tomcat -->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-tomcat</artifactId>
<scope>provided</scope>
</dependency>
<!-- Slug generator -->
<dependency>
<groupId>com.github.slugify</groupId>
<artifactId>slugify</artifactId>
<version>2.1.7</version>
</dependency>
<!-- Common String -->
<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-lang3</artifactId>
<version>3.4</version>
</dependency>
<!-- Apache Commons IO -->
<dependency>
<groupId>commons-io</groupId>
<artifactId>commons-io</artifactId>
<version>2.4</version>
</dependency>
<!-- JSTL for JSP -->
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>jstl</artifactId>
<scope>provided</scope>
</dependency>
<!-- Need this to compile JSP -->
<dependency>
<groupId>org.apache.tomcat.embed</groupId>
<artifactId>tomcat-embed-jasper</artifactId>
<scope>provided</scope>
</dependency>
<!-- Need this to compile JSP,
tomcat-embed-jasper version is not working, no idea why -->
<dependency>
<groupId>org.eclipse.jdt.core.compiler</groupId>
<artifactId>ecj</artifactId>
<version>4.6.1</version>
<scope>provided</scope>
</dependency>
<!-- Optional, test for static content, bootstrap CSS-->
<dependency>
<groupId>org.webjars</groupId>
<artifactId>bootstrap</artifactId>
<version>3.3.7</version>
</dependency>
<dependency>
<groupId>org.postgresql</groupId>
<artifactId>postgresql</artifactId>
</dependency>
<dependency>
<groupId>org.apache.httpcomponents</groupId>
<artifactId>httpclient</artifactId>
<version>4.3.5</version>
</dependency>
<dependency>
<groupId>org.apache.httpcomponents</groupId>
<artifactId>httpcore</artifactId>
<version>4.4.6</version>
</dependency>
<!-- https://mvnrepository.com/artifact/com.jcabi/jcabi-xml -->
<dependency>
<groupId>com.jcabi</groupId>
<artifactId>jcabi-xml</artifactId>
<version>0.18.1</version>
</dependency>
<!-- https://mvnrepository.com/artifact/joda-time/joda-time -->
<dependency>
<groupId>joda-time</groupId>
<artifactId>joda-time</artifactId>
<version>2.3</version>
</dependency>
<dependency>
<groupId>com.google.code.gson</groupId>
<artifactId>gson</artifactId>
<version>2.2.4</version>
</dependency>
</dependencies>
<build>
<plugins>
<!-- Spring boot maven support -->
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
</build>
</project>
应用程序类如下:
package com.sdigital;
import java.util.Map;
import java.util.concurrent.TimeUnit;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.context.annotation.Bean;
import com.sdigital.cache.ExpiringMap;
/**
* The Class CTTApplication.
*/
@SpringBootApplication
public class CTTApplication {
/**
* The main method.
*boots the application
*
*/
public static void main(String[] args) {
SpringApplication.run(CTTApplication.class, args);
}
@Bean
public Map<String, Object> getCache(){
Map<String, Object> map = ExpiringMap.builder()
.maxSize(200)
.expiration(12, TimeUnit.HOURS)
.build();
return map;
}
}
ServletInitializer
package com.sdigital;
import org.springframework.boot.builder.SpringApplicationBuilder;
import org.springframework.boot.context.web.SpringBootServletInitializer;
// TODO: Auto-generated Javadoc
/**
* The Class ServletInitializer.
*/
public class ServletInitializer extends SpringBootServletInitializer {
/* (non-Javadoc)
* SpringApplication Builder
*/
@Override
protected SpringApplicationBuilder configure(SpringApplicationBuilder application) {
return application.sources(CTTApplication.class);
}
}
控制器
package com.sdigital.controller;
import java.net.URISyntaxException;
import java.util.Date;
import java.util.List;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.SessionAttributes;
import org.springframework.web.servlet.ModelAndView;
import com.sdigital.bus.distribution.domain.ConnectionRequest;
import com.sdigital.cache.SearchCache;
import com.sdigital.domain.JourneyRequest;
import com.sdigital.domain.TimeTableRequest;
import com.sdigital.domain.XmlUrl;
import com.sdigital.domain.XmlUrlSet;
import com.sdigital.model.BusProvider;
import com.sdigital.model.City;
import com.sdigital.model.CustomForm;
import com.sdigital.model.Route;
import com.sdigital.model.SeoConfig;
import com.sdigital.model.SiteMap;
import com.sdigital.repositories.BusProviderRepository;
import com.sdigital.repositories.CityRepository;
import com.sdigital.repositories.RouteRepository;
import com.sdigital.repositories.SeoConfigRepository;
import com.sdigital.repositories.SiteMapRepository;
import com.sdigital.repositories.StationConfigRepository;
import com.sdigital.service.AppService;
import com.sdigital.utils.CTTConstant;
import com.sdigital.utils.CommonUtils;
@Controller
@SessionAttributes({"searchRequest", "searchBusRequest"})
public class AppController {
@Autowired
private AppService appServc;
@Autowired
private StationConfigRepository strepo;
@Autowired
private RouteRepository rtrepo;
@Autowired
private CityRepository ctrepo;
@Autowired
private BusProviderRepository busrepo;
@Autowired
private SeoConfigRepository repo;
@Autowired
private SearchCache searchCache;
@Autowired
private SiteMapRepository siteMap;
@RequestMapping("/")
public ModelAndView home(){
//List<Route> cttPopular = rtrepo.findOneByPopularType(CTTConstant.CTT_POPULAR_TYPE);
List<City> cttPopular = ctrepo.findAllByOrderByPriorityAsc();
List<Route> popular = rtrepo.findByPopularType(CTTConstant.POPULAR_TYPE);
ModelAndView model = new ModelAndView("index");
model.addObject("cttPopular", cttPopular);
model.addObject("popular", popular);
SeoConfig seoCon = repo.findByPageType(3);
model.addObject("title", seoCon.getPageTitle());
model.addObject("meta_title", seoCon.getMetaTitle());
model.addObject("meta_description", seoCon.getMetaDescription());
model.addObject("meta_keywords", seoCon.getMetaKeywords());
model.addObject("seo_url", seoCon.getSeoUrl());
model.addObject("description", seoCon.getDescription());
model.addObject("desc1", seoCon.getDesc1());
model.addObject("desc2", seoCon.getDesc2());
model.addObject("desc3", seoCon.getDesc3());
List<City> topCities = ctrepo.findTop10ByOrderByPriorityAsc();
List<Route> topRoutes = rtrepo.findTop10ByOrderByPriorityAsc();
model.addObject("topCities", topCities);
model.addObject("topRoutes", topRoutes);
List<BusProvider> topBusProviders = busrepo.findTop10ByPublishOrderByPriorityAsc(true);
model.addObject("topBusProviders", topBusProviders);
return model;
}
@RequestMapping(value = "/book")
public ModelAndView portalBook(@ModelAttribute("journeyRequest") JourneyRequest journeyRequest) throws URISyntaxException {
ModelAndView m = null;
m = appServc.getView(journeyRequest);
return m;
}
@RequestMapping(value="/search")
public ModelAndView portalSearch(@ModelAttribute("searchRequest") TimeTableRequest searchRequest,
@RequestParam(name="sort_by", required = false) String sortBy,
@RequestParam(name="s", required = false) String start,
@RequestParam(name="orig", required = false) String originuic,
@RequestParam(name="dest", required = false) String destinationuic, HttpSession session){
/*System.out.println("*** Session data ***");
Enumeration<String> e = session.getAttributeNames();
while (e.hasMoreElements()){
String s = e.nextElement();
System.out.println(s);
System.out.println("**" + session.getAttribute(s));
}*/
if(originuic!=null && destinationuic!=null){
searchRequest.setChildren(0);
searchRequest.setRailcards(null);
searchRequest.setTravelclass("standard");
searchRequest.setRetdatetime(null);
searchRequest.setAdults(1);
searchRequest.setDestinationuic(destinationuic);
searchRequest.setOriginuic(originuic);
searchRequest.setReturnjry(false);
searchRequest.setOutdatetime(CommonUtils.getFormatedDate(CTTConstant.DEFAULT_SEARCH_FORMAT, new Date()));
searchRequest.setOutsearchTime(CommonUtils.getCurrentUTCTimeSearchable(false));
}
ModelAndView m = appServc.getView(searchRequest, sortBy, start);
List<City> topCities = ctrepo.findTop10ByOrderByPriorityAsc();
List<Route> topRoutes = rtrepo.findTop10ByOrderByPriorityAsc();
m.addObject("topCities", topCities);
m.addObject("topRoutes", topRoutes);
List<BusProvider> topBusProviders = busrepo.findTop10ByPublishOrderByPriorityAsc(true);
m.addObject("topBusProviders", topBusProviders);
m.addObject("currentDate", CommonUtils.getFormatedDate(CTTConstant.DEFAULT_SEARCH_FORMAT, new Date()));
return m;
}
@ModelAttribute("searchRequest")
public TimeTableRequest createFormModelAttribute(HttpSession session) {
TimeTableRequest req = (TimeTableRequest)session.getAttribute("searchRequest");
if(req!=null)
return req;
TimeTableRequest req1 = new TimeTableRequest();
req1.setAdults(1);
req1.setOutdatetime(CommonUtils.getFormatedDate(CTTConstant.DEFAULT_SEARCH_FORMAT, new Date()));
req1.setOutsearchTime(CommonUtils.getCurrentUTCTimeSearchable(false));
req1.setRetsearchTime(CommonUtils.getCurrentUTCTimeSearchable(true));
return req1;
}
@RequestMapping(value="/bus-search")
public ModelAndView portalSearch(@ModelAttribute("searchBusRequest") ConnectionRequest searchRequest,
@RequestParam(name="sort_by", required = false) String sortBy,
@RequestParam(name="s", required = false) String start,
@RequestParam(name="orig", required = false) String originuic,
@RequestParam(name="dest", required = false) String destinationuic, HttpSession session){
if(originuic!=null && destinationuic!=null){
searchRequest.setChildren1(0);
searchRequest.setRetdatetime(null);
searchRequest.setAdults1(1);
searchRequest.setDestinationuic1(destinationuic);
searchRequest.setOriginuic1(originuic);
searchRequest.setReturnjry(false);
searchRequest.setCurrency("EUR");
searchRequest.setDatetime(CommonUtils.getFormatedDate(CTTConstant.DEFAULT_SEARCH_FORMAT, new Date()));
}
ModelAndView m = appServc.getView(searchRequest, sortBy, start);
List<City> topCities = ctrepo.findTop10ByOrderByPriorityAsc();
List<Route> topRoutes = rtrepo.findTop10ByOrderByPriorityAsc();
m.addObject("topCities", topCities);
m.addObject("topRoutes", topRoutes);
List<BusProvider> topBusProviders = busrepo.findTop10ByPublishOrderByPriorityAsc(true);
m.addObject("topBusProviders", topBusProviders);
m.addObject("currentDate", CommonUtils.getFormatedDate(CTTConstant.DEFAULT_SEARCH_FORMAT, new Date()));
return m;
}
@ModelAttribute("searchBusRequest")
public ConnectionRequest createFormModelAttribute() {
return new ConnectionRequest();
}
@ModelAttribute("journeyRequest")
public JourneyRequest createFormModelAttribute1() {
return new JourneyRequest();
}
@RequestMapping(value="/{seo:.+}")
public ModelAndView portalLocation(@PathVariable("seo") String seo, HttpServletResponse response, @RequestParam(name="status", required = false) String status){
ModelAndView m = appServc.getView(seo, response, status);
List<City> topCities = ctrepo.findTop10ByOrderByPriorityAsc();
List<Route> topRoutes = rtrepo.findTop10ByOrderByPriorityAsc();
m.addObject("topCities", topCities);
m.addObject("topRoutes", topRoutes);
List<BusProvider> topBusProviders = busrepo.findTop10ByPublishOrderByPriorityAsc(true);
m.addObject("topBusProviders", topBusProviders);
return m;
}
@RequestMapping(value="/{seo1}/{seo2:.+}")
public ModelAndView portalChildLocation(@PathVariable("seo1") String seo1, @PathVariable("seo2") String seo2, HttpServletResponse response, @RequestParam(name="status", required = false) String status){
ModelAndView m = appServc.getView(seo1+"/"+seo2, response, status);
List<City> topCities = ctrepo.findTop10ByOrderByPriorityAsc();
List<Route> topRoutes = rtrepo.findTop10ByOrderByPriorityAsc();
m.addObject("topCities", topCities);
m.addObject("topRoutes", topRoutes);
List<BusProvider> topBusProviders = busrepo.findTop10ByPublishOrderByPriorityAsc(true);
m.addObject("topBusProviders", topBusProviders);
return m;
}
@ResponseBody
@RequestMapping(value="/schedular/trains")
public boolean portalSchedularToUpdateTrains(){
appServc.updateTrainsForCityToCity();
return true;
}
@RequestMapping(value = "/robots.txt")
@ResponseBody
public String getRobots(HttpServletRequest request) {
return "User-agent: * \n Disallow: /";
}
@RequestMapping(value = "/sitemap.xml", method = RequestMethod.GET)
@ResponseBody
public XmlUrlSet getSiteMap(HttpServletRequest request) {
XmlUrlSet xmlUrlSet = new XmlUrlSet();
create(xmlUrlSet, "", "1.0", request);
List<SiteMap> seoUrls = siteMap.findByPublish(1);
for(SiteMap sUrl : seoUrls){
create(xmlUrlSet, "/"+sUrl.getSeoUrl(), null, request);
}
return xmlUrlSet;
}
private void create(XmlUrlSet xmlUrlSet, String link, String priority, HttpServletRequest request) {
String rootUrl = request.getScheme() + "://" + request.getServerName() + request.getContextPath();
xmlUrlSet.addUrl(new XmlUrl(rootUrl + link, priority));
}
@RequestMapping(value="/information/rail-cards")
public ModelAndView railCardInfo(){
ModelAndView model = new ModelAndView("railinfo");
return model;
}
@RequestMapping(value="/form/post")
public String formPost(@ModelAttribute("addRequest") CustomForm addRequest){
String r = appServc.addData(addRequest);
return r;
}
@ExceptionHandler(Exception.class)
public ModelAndView handleError(HttpServletRequest req, Exception ex) {
ModelAndView m = new ModelAndView("exception");
List<City> topCities = ctrepo.findTop10ByOrderByPriorityAsc();
List<Route> topRoutes = rtrepo.findTop10ByOrderByPriorityAsc();
m.addObject("topCities", topCities);
m.addObject("topRoutes", topRoutes);
List<BusProvider> topBusProviders = busrepo.findTop10ByPublishOrderByPriorityAsc(true);
m.addObject("topBusProviders", topBusProviders);
m.addObject("searchRequest", new TimeTableRequest());
return m;
}
}
答案 0 :(得分:0)
添加我的答案,以防其他人遇到相同的问题。 问题出在上下文路径上。在Eclipse中更新了项目属性中的上下文路径。然后跑干净并建造。最重要的部分是删除服务器配置,然后再次在tomcat上运行它。
由于我没有从eclipse更新的上下文路径中清除服务器配置,因此无法使用。