spark-javaフレームワークを使用してJavaアプリケーションを作成しました。私は.jarファイルをビルドし、コマンドラインから実行し、ブラウザのhttp://localhost:4567/helloに行きます。それは働いた、ここに問題はない。.jar AWS Elastic BeanstalkでSpark-Javaアプリケーションが実行されない
次に、私はElastic Beanstalkアプリケーションを作成し、その.jarファイルをデプロイしました。それは正常に展開されました。しかし、私のElastic Beanstalk環境(http://spark-test.eu-central-1.elasticbeanstalk.com/)のURLをクリックすると、 "502 Bad Gateway"エラーが返されました。
ウェブ上で同様の質問と回答が表示されていますが、いずれも機能しませんでした。問題はどこだ?どうすれば解決できますか?ここで
メインクラスです。ここ
import static spark.Spark.*;
public class Main {
public static void main(String[] args) {
get("/hello", (req, res) -> "Hello World");
get("/hello/:name", (request, response) -> {
return "Hello " + request.params(":name");
});
}
}
はの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.myapps</groupId>
<artifactId>spark-test</artifactId>
<version>1.0-SNAPSHOT</version>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<source>1.8</source>
<target>1.8</target>
</configuration>
</plugin>
</plugins>
</build>
<dependencies>
<dependency>
<groupId>com.sparkjava</groupId>
<artifactId>spark-core</artifactId>
<version>2.5</version>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-simple</artifactId>
<version>1.7.22</version>
</dependency>
</dependencies>
</project>
Tomcatで実行できます。私は.warファイルを作成し、Elastic Beanstalk Tomcat環境にデプロイしました。問題なく動作しました。しかし、私は.jarファイルを作成し、Elastic Beanstalk Java環境でデプロイして実行したいと考えています。通常のJava SEプロジェクト(Java Webアプリケーションプロジェクトではなく、web.xmlを作成および変更しない)を作成し、.jarファイルを作成してElastic Beanstalk Java環境にデプロイすることは可能ですか? – cimenmus