E
E
Evgeny Kolman2019-04-07 09:25:37
Java
Evgeny Kolman, 2019-04-07 09:25:37

Can't deploy war to external server on Tomcat?

Good afternoon!
I am writing my project in spring. I took an example from the Spring documentation
Then I build war Gradle build
The structure of my project is the same as in the example
Here is my Gradle file:

buildscript {
  repositories {
    mavenCentral()
  }
  dependencies {
    classpath("org.springframework.boot:spring-boot-gradle-plugin:2.0.5.RELEASE")
  }
}

apply plugin: 'java'
apply plugin: 'eclipse'
apply plugin: 'idea'
apply plugin: 'org.springframework.boot'
apply plugin: 'io.spring.dependency-management'

bootJar {
  baseName = 'gs-serving-web-content'
  version =  '0.1.0'
}

repositories {
  mavenCentral()
}

sourceCompatibility = 1.8
targetCompatibility = 1.8

dependencies {
  compile("org.springframework.boot:spring-boot-starter-web")
  compile("org.springframework.boot:spring-boot-starter-thymeleaf")
  compile("org.springframework.boot:spring-boot-devtools")
  testCompile("junit:junit")
}

Here is my controller:
package com.pathfinderPrj.pathfinderPrj;

import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestParam;

@Controller
public class StartController {
    @GetMapping("/greeting")
    public String greeting(@RequestParam(name="name", required=false, defaultValue="World") String name, Model model) {
        model.addAttribute("name", name);
        return "greeting";
    }
}

After I try to deploy my war on an external and local Tomcat and I get an error:
HTTP Status 404 – Not Found

Type Status Report

Message /pathfinderPrj_war_exploded/

Description The origin server did not find a current representation for the target resource or is not willing to disclose that one exists.

Maybe someone faced such a problem, why Tomcat does not see my htnl page? Maybe you need to somehow change the path where the html is?
Thank you very much in advance!

Answer the question

In order to leave comments, you need to log in

1 answer(s)
O
Orkhan, 2019-04-07
Hasanly @azerphoenix

It's strange, just yesterday I answered your question... And for some reason it was deleted and you re-posted the same question...
1) Please clarify, do you build war or use exploded war? Are you building war correctly in Intellij IDEA? True, it is not always correctly assembled automatically if you select "From modules and dependencies" ...
2) Have you taken into account the context path on the remote tomcate? For example, if you run your application locally like this: localhost:8080/greeningthen, taking into account the context path, remotely, it will look like this localhost:8080/pathfinderPrj_war_exploded/greeting
In application properties, write - server.servlet.context-path=/YoutContextPathHere
3) Yesterday I wrote about the fact that you use the thymeleaf template engine. Accordingly, the place of hardcoding type references is href="/greeting"to use its syntaxth:href="@{/greeting}"
Also, for the future... if there is an error on the server side, you can raise the TomCat logs at any time

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question