Я новенький в java и весной. Мое приложение без проблем работает в Intellijj IDE
на windows, но я попытался экспортировать .war и развернуть его через веб-интерфейс tomcat (/manager/html
), и приложение выглядит как развернутое, потому что я вижу папку в веб-приложениях, но приложение не за работой. что я сделал не так? Для меня зависимости Spring Boot и Tomcat выглядят нормально, класс приложения также расширяет SpringBootServletInitializer. Как проверить, это проблема с Tomcat или проблема с моим приложением? Большое спасибо за ответы заранее Projec structure">
Application main class:
package com.borisprog.parking;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.builder.SpringApplicationBuilder;
import org.springframework.boot.web.servlet.support.SpringBootServletInitializer;
@SpringBootApplication
public class ParkingApplication extends SpringBootServletInitializer {
public static void main(String[] args) {
SpringApplication.run(ParkingApplication.class, args);
}
protected SpringApplicationBuilder configure(SpringApplicationBuilder builder) {
return builder.sources(ParkingApplication.class);
}
}
контроллер
@Controller
public class MainController {
@Autowired
private TrailerRepository trailerRepository;
@GetMapping("/login")
public String login(Model model) {
return "login";
}
@GetMapping("/")
public String home(Model model) {
model.addAttribute("title", "");
//Iterable<Trailer> trailers = trailerRepository.findAll(Sort.by("inDate").ascending());
Iterable<Trailer> trailers = trailerRepository.findByOutTrcIsNull(Sort.by("inDate").ascending());
model.addAttribute("trailers", trailers);
return "arrived";
}
@GetMapping("/arrived")
public String arrived (Model model) {
model.addAttribute("title", "Glavnaja stranica");
//Iterable<Trailer> trailers = trailerRepository.findAll(Sort.by("inDate").ascending());
Iterable<Trailer> trailers = trailerRepository.findByOutTrcIsNull(Sort.by("inDate").ascending());
model.addAttribute("trailers", trailers);
return "arrived";
}
@GetMapping("/depart")
public String depart(Model model) {
model.addAttribute("title", "Glavnaja stranica");
//Iterable<Trailer> trailers = trailerRepository.findAll(Sort.by("inDate").ascending());
Iterable<Trailer> trailers = trailerRepository.findByOutTrcNotNull(Sort.by("outDate").descending());
model.addAttribute("trailers", trailers);
return "depart";
}
@GetMapping("/all")
public String all(Model model) {
model.addAttribute("title", "Glavnaja stranica");
// Iterable<Trailer> trailers = trailerRepository.findAll(Sort.by("outDate").ascending());
// model.addAttribute("trailers", trailers);
return "all";
}
// add Arrival permit
@RequestMapping(value = "/trl/add", method = RequestMethod.POST)
public String trlAdd (@RequestParam String inTrl, @RequestParam Date inDate, @RequestParam String dep, @RequestParam String inTruck, @RequestParam String inName, @RequestParam String inLname, Model model) {
Trailer trailer = new Trailer(inTrl, inTruck, inName, inLname, dep, inDate);
System.out.println("Model created");
Tools tools = new Tools();
try {
tools.createExcel("IMPORT",inName,inLname,inTruck,inTrl,inDate.toString());
} catch (IOException | InvalidFormatException e) {
e.printStackTrace();
}
//tools.sendMail("ar1an@mail.ru","IMPORT", inTruck, inTrl, inName, inLname, inDate.toString());
tools.sendEmail("IMPORT", inTruck,inTrl,inName,inLname,inDate.toString());
//tools.copyFile("IMPORT",inTruck+"-"+inTrl,inDate.toString());
trailerRepository.save(trailer);
System.out.println("Trailer saved");
return "result";
//return "redirect:/arrived";
}
// Add departure pertmit
@PostMapping(value = "/dep")
public String trlDepart ( @RequestParam Long id, @RequestParam Date outDate, @RequestParam String dep, @RequestParam String outTruck, @RequestParam String outTrl, @RequestParam String outName, @RequestParam String outLname, Model model) {
Trailer trailer = trailerRepository.findById(id).orElseThrow();
trailer.setOutDate(outDate);
trailer.setOutTrc(outTruck);
trailer.setOutName(outName);
trailer.setOutLname(outLname);
trailer.setDepartment(dep);
Tools tools = new Tools();
try {
tools.createExcel("EXPORT",outName,outLname,outTruck,outTrl,outDate.toString());
} catch (IOException | InvalidFormatException e) {
e.printStackTrace();
}
tools.sendEmail("EXPORT", outTruck,outTrl,outName,outLname,outDate.toString());
trailerRepository.save(trailer);
return "redirect:/arrived";
}
@RequestMapping(value = "/editarr", method = RequestMethod.POST)
public String trlEditArr ( @RequestParam Long id, @RequestParam Date inDate, @RequestParam String dep, @RequestParam String inTruck, @RequestParam String inName, @RequestParam String inLname, Model model) {
Trailer trailer = trailerRepository.findById(id).orElseThrow();
trailer.setInDate(inDate);
trailer.setInTrc(inTruck);
trailer.setInName(inName);
trailer.setInLname(inLname);
trailer.setDepartment(dep);
trailerRepository.save(trailer);
return "result";
//return "redirect:/arrived";
}
@RequestMapping(value = "/loadtype", params = "export", method = RequestMethod.POST)
// public String export (Model model, @RequestParam Date datefrom, Date dateto){
//
public void downloadCsv(HttpServletResponse response, Model model, @RequestParam Date datefrom, Date dateto) throws IOException {
response.setContentType("application/octet-stream");
response.setHeader("Content-Disposition", "attachment; filename=Report.xlsx");
ByteArrayInputStream stream = ExcelFileExporter.contactListToExcelFile(createTestData(datefrom, dateto));
IOUtils.copy(stream, response.getOutputStream());
}
private List<Trailer> createTestData(Date datefrom, Date dateto){
// public Trailer(String trl, String inTrc, String inName, String inLname, String department, Date inDate)
SimpleDateFormat formatter= new SimpleDateFormat("yyyy-MM-dd 'at' HH:mm:ss z");
Date date = new Date(System.currentTimeMillis());
Iterable<Trailer> trailers = trailerRepository.findTop1000ByInDateBetweenOrderByInDateDesc(datefrom, dateto);
List<Trailer> trl = new ArrayList<>();
trailers.forEach(trl::add);
System.out.println("======Method EXPORT called======");
return trl;
}
@RequestMapping(value = "/loadtype", params = "load", method = RequestMethod.POST)
public String load (Model model, @RequestParam Date datefrom, Date dateto ){
System.out.println("======Method LOAD called======");
Iterable<Trailer> trailers = trailerRepository.findTop1000ByInDateBetweenOrderByInDateDesc(datefrom, dateto);
model.addAttribute("trailers", trailers);
return "/all";
}
@RequestMapping(value = "/removearr", method = RequestMethod.POST)
public String trlRemoveArr ( @RequestParam Long id, Model model) {
trailerRepository.deleteById(id);
return "redirect:/arrived";
}
@RequestMapping(value = "/editdep", method = RequestMethod.POST)
public String trlEditDep ( @RequestParam Long id, @RequestParam Date outDate, @RequestParam String dep, @RequestParam String outTruck, @RequestParam String outName, @RequestParam String outLname, Model model) {
Trailer trailer = trailerRepository.findById(id).orElseThrow();
trailer.setOutDate(outDate);
trailer.setOutTrc(outTruck);
trailer.setOutName(outName);
trailer.setOutLname(outLname);
trailer.setDepartment(dep);
trailerRepository.save(trailer);
return "redirect:/depart";
}
@RequestMapping(value = "/removedep", method = RequestMethod.POST)
public String trlRemoveDep ( @RequestParam Long id, @RequestParam String dep, Model model) {
Trailer trailer = trailerRepository.findById(id).orElseThrow();
trailer.setOutDate(null);
trailer.setOutTrc(null);
trailer.setOutName(null);
trailer.setOutLname(null);
trailer.setDepartment(dep);
trailerRepository.save(trailer);
return "redirect:/depart";
}
}
пом. 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 https://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.2.5.RELEASE</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>
<groupId>com.borisprog</groupId>
<artifactId>parking</artifactId>
<description>Demo project for Spring Boot</description>
<name>parking</name>
<properties>
<java.version>1.8</java.version>
</properties>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-thymeleaf</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-tomcat</artifactId>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>javax.servlet-api</artifactId>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-devtools</artifactId>
<scope>runtime</scope>
<optional>true</optional>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-jpa</artifactId>
</dependency>
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<scope>runtime</scope>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
<exclusions>
<exclusion>
<groupId>org.junit.vintage</groupId>
<artifactId>junit-vintage-engine</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-security</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.security</groupId>
<artifactId>spring-security-test</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.apache.poi</groupId>
<artifactId>poi</artifactId>
<version>3.15</version>
</dependency>
<dependency>
<groupId>org.apache.poi</groupId>
<artifactId>poi-ooxml</artifactId>
<version>3.15</version>
</dependency>
<dependency>
<groupId>com.sun.mail</groupId>
<artifactId>javax.mail</artifactId>
<version>1.6.2</version>
</dependency>
</dependencies>
<packaging>war</packaging>
<build>
<finalName>${artifactId}</finalName>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<source>10</source>
<target>10</target>
</configuration>
</plugin>
<plugin>
<artifactId>maven-war-plugin</artifactId>
<version>2.1.1</version>
<configuration>
<attachClasses>true</attachClasses>
</configuration>
</plugin>
</plugins>
</build>
</project>
Журналы:
журнал каталины: http://txt.do/1qp8s
журнал локального хоста: http://txt.do/1qp85
журнал локального доступа: http://txt.do/1qp81