I'm very new at both AWS and Spring Framework.
I've built a simple web program following the getting started guide in Spring website. Also, I already made my Elastic Beanstalk application and environment running Tomcat 8 and Java 8. What I'm trying to is;
- build this simple program using Gradle and produce an executable jar( or war).
- upload this executable jar(or war) from 'upload and deploy' button in my Elastic Beanstalk dashboard.
I'm using IntelliJ now and my program works well if I double-clicked the produced executable jar. However, after I uploaded this jar to my Elastic Beanstalk, this program just produces HTTP 404 error.
What I don't understand is, if I use Gradle 'build' task or 'bootRun' task, the produced executable jar file works fine. However, if I build a war file through Gradle 'war' task and put it on my local Tomcat, the server produces HTTP 404 error same as AWS.
This is my build.gradle file.
buildscript {
repositories {
mavenCentral()
}
dependencies {
classpath("org.springframework.boot:spring-boot-gradle-plugin:1.2.7.RELEASE")
classpath("org.apache.tomcat:tomcat-catalina:8.0.28")
}
}
apply plugin: 'java'
apply plugin: 'eclipse'
apply plugin: 'idea'
apply plugin: 'spring-boot'
apply plugin: 'war'
jar {
baseName = 'gs-authenticating-ldap'
version = '0.1.0'
}
war {
baseName = 'gs-authenticating-ldap'
version = '0.1.0'
}
repositories {
mavenCentral()
}
sourceCompatibility = 1.8
targetCompatibility = 1.8
dependencies {
compile("org.springframework.boot:spring-boot-starter-web")
testCompile("junit:junit")
}
task wrapper(type: Wrapper) {
gradleVersion = '2.3'
}
Besides, my program only has two Java classes: src/main/java/hello/HomeController.java and src/main/java/hello/Application.java
src/main/java/hello/HomeController.java is:
package hello;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
@RestController
public class HomeController {
@RequestMapping("/")
public String index() {
return "Welcome to the home page!";
}
}
src/main/java/hello/Application.java is:
package hello;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
@SpringBootApplication
public class Application {
public static void main(String[] args) {
SpringApplication.run(Application.class, args);
}
}
As a summary:
- build 'bootRun' -> browse "localhost:8080" : Works fine.
- build 'build' -> produce 'xxx.jar(executable)' -> double click to execute this jar -> browse "localhost:8080" : Works fine
- build 'build' -> produce 'xxx.jar(executable)' -> upload to AWS -> browse "xx.elasticbeanstalk.com" : HTTP 404 error
- build 'war' -> produce 'xxx.war' -> run this war on local Tomcat using IntelliJ -> browse "localhost:8080" : HTTP 404 error
- build 'war' -> produce 'xxx.war' -> upload to AWS -> browse "xx.elasticbeanstalk.com" : HTTP 404 error
What I want to do is 1) develop on IntelliJ, 2) build it on Gradle, 3) test it on locally, and 4) upload it on AWS to run. Please, help me.
If you have any further explanation or information, please let me know. Thanks!