1
votes

I try to deploy Gradle + Spring Boot 2 + Angular2 app WAR file on standalone Tomcat 7.0.91. If I boot application with provided jar and embedded tomcat everything works ok, but when deploying on standalone container when I go to "/springboot" context it gives me 404: "The origin server did not find a current representation for the target resource or is not willing to disclose that one exists." Logs from tomcat don't tell anything usefull. I tried 2 approaches of deployment, by setting in server.xml context path and doc base:

<Host name="localhost"  appBase="webapps" unpackWARs="true" autoDeploy="true">
    <Context path="/springboot" docBase="/home/user/SideProjects/springboot-angular2-gradle-war/build/libs"/>                                                     
</Host>

And second was deploying war file "by hand" in webapps directory.

I'm not sure but file context.xml in tomcat is set to watch resources in WEB-INF/web.xml but as I know, spring boot doesn't use web.xml anymore so maybe that's the case? Unfortunatelly every tutorial i found didn't tell anything about changing context.xml, moreover i can't find what resource in spring is considered as deployment descriptor nowadays.

That's my build.gradle file:

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

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

apply plugin: 'application'
mainClassName = "com.demo.SpringbootAngular2GradleWarApplication"

group = 'com.demo'
version = '0.0.1-SNAPSHOT'
sourceCompatibility = 1.8

war {
    baseName = "demo-spring"
}

repositories {
    mavenCentral()
}

configurations {
    providedRuntime
}

dependencies {
    compile('org.springframework.boot:spring-boot-starter-web')
    providedRuntime('org.springframework.boot:spring-boot-starter-tomcat')
    testCompile('org.springframework.boot:spring-boot-starter-test')
}


def frontendDir = "$projectDir/src/main/frontend"
def frontDistDir = "$frontendDir/dist"

sourceSets {
    main {
        resources {
            srcDirs = ["$frontDistDir", "$projectDir/src/main/resources"]
        }
    }
}

clean.doFirst {
    delete "$frontDistDir"
    println "$frontDistDir - cleaned"
}

task buildAngular(type: Exec) {
    workingDir "$frontendDir"
    inputs.dir "$frontendDir"
    commandLine "npm", "run-script", "build"
}

processResources.dependsOn "buildAngular"

Main class extends servlet initializer:

 package com.demo;

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 SpringbootAngular2GradleWarApplication extends SpringBootServletInitializer {

    @Override
    protected SpringApplicationBuilder configure(SpringApplicationBuilder builder) {
        return builder.sources(SpringbootAngular2GradleWarApplication.class);
    }

    public static void main(String[] args) {
        SpringApplication.run(SpringbootAngular2GradleWarApplication.class, args);
    }
}
1
Your app is named demo-spring so when deploying the war the url will be something like http://localhost:8080/demo-spring-0.0.1-SNAPSHOT. - M. Deinum
Unfortunately it is not the case. I don't know why but that way of changing name doesn't work and gradle still generates default name: springboot-angular2-gradle-war-0.0.1-SNAPSHOT.war anyway "path" property in context settings sets the name i want - Piotr Bartoch
It would if it points to some valid location. Pointing it at the directory containing the war won't do anything. Also when dropping the war the context path is ignored and it would be springboot-angular2-gradle-war-0.0.1-SNAPSHOT as the path. However I suggest including a context.xml in your war in the META-INF folder (AFAIK) to set the path. - M. Deinum
What exactly should i set in context.xml ? I assume it should be done in XmlConfiguration class? Dropping file in webapps and not renaming it, so i use full name as context path, still causes 404 - Piotr Bartoch

1 Answers

1
votes

Problem was with versions incompatibility, minimum Tomcat version supported by SpringBoot-2 is 8.5.x in order to el-api and more. Actually dropping war in webapps and renaming it "by hand" works.