初めて質問します。
不足している情報や不手際がありましたら申し訳ありません。
コメント欄にて確認していただけると幸いです。
前提・実現したいこと
Spring Bootフレームワークを用いて、webアプリケーションを開発しています。
このアプリケーションをjarで吐き出して実行しても動かず困っています。
cmd
1> java -jar example-ver-0.1.jar
将来的には、EC2に乗せて動かしたいと思っています。
開発環境であるEclipse上では動いており、パッケージにする際に何かが足りていないのでは、と考えています。
発生している問題・エラーメッセージ
[main] INFO com.example.exampleApplication - Starting exampleApplication on xxx-001 with PID 13964 (C:\pleiades\workspace\example-ver\build\libs\example-ver-0.1.jar started by xxx in c:\pleiades\workspace\example-ver\build\libs) [main] DEBUG com.example.exampleApplication - Running with Spring Boot, Spring [main] INFO com.example.exampleApplication - No active profile set, falling back to default profiles: default [main] DEBUG org.springframework.boot.SpringApplication - Loading source class com.example.exampleApplication [main] DEBUG org.springframework.boot.web.servlet.context.AnnotationConfigServletWebServerApplicationContext - Refreshing org.springframework.boot.web.servlet.context.AnnotationConfigServletWebServerApplicationContext@376b4233 [main] DEBUG org.springframework.beans.factory.support.DefaultListableBeanFactory - Creating shared instance of singleton bean 'org.springframework.context.annotation.internalConfigurationAnnotationProcessor' [main] DEBUG org.springframework.context.annotation.ClassPathBeanDefinitionScanner - Ignored because not a concrete top-level class: URL [jar:file:/C:/pleiades/workspace/example-ver/build/libs/example-ver-0.1.jar!/com/example/domain/repository/XXX_Repository.class] ・・・ [main] DEBUG org.springframework.context.annotation.ClassPathBeanDefinitionScanner - Identified candidate component class: URL [jar:file:/C:/pleiades/workspace/example-ver/build/libs/example-ver-0.1.jar!/com/example/service/XXX_Service.class] ・・・ [main] DEBUG org.springframework.context.annotation.ClassPathBeanDefinitionScanner - Identified candidate component class: URL [jar:file:/C:/pleiades/workspace/example-ver/build/libs/example-ver-0.1.jar!/com/example/web/XXX_Controller.class] ・・・ [main] DEBUG org.springframework.beans.factory.support.DefaultListableBeanFactory - Creating shared instance of singleton bean 'org.springframework.context.event.internalEventListenerProcessor' [main] DEBUG org.springframework.beans.factory.support.DefaultListableBeanFactory - Creating shared instance of singleton bean 'org.springframework.context.event.internalEventListenerFactory' [main] DEBUG org.springframework.beans.factory.support.DefaultListableBeanFactory - Creating shared instance of singleton bean 'org.springframework.context.annotation.internalAutowiredAnnotationProcessor' [main] DEBUG org.springframework.beans.factory.support.DefaultListableBeanFactory - Creating shared instance of singleton bean 'org.springframework.context.annotation.internalCommonAnnotationProcessor' [main] DEBUG org.springframework.beans.factory.support.DefaultListableBeanFactory - Creating shared instance of singleton bean 'org.springframework.context.annotation.internalPersistenceAnnotationProcessor' [main] DEBUG org.springframework.ui.context.support.UiApplicationContextUtils - Unable to locate ThemeSource with name 'themeSource': using default [org.springframework.ui.context.support.ResourceBundleThemeSource@70e9c95d] [main] WARN org.springframework.boot.web.servlet.context.AnnotationConfigServletWebServerApplicationContext - Exception encountered during context initialization - cancelling refresh attempt: org.springframework.context.ApplicationContextException: Unable to start web server; nested exception is org.springframework.context.ApplicationContextException: Unable to start ServletWebServerApplicationContext due to missing ServletWebServerFactory bean. [main] ERROR org.springframework.boot.SpringApplication - Application run failed org.springframework.context.ApplicationContextException: Unable to start web server; nested exception is org.springframework.context.ApplicationContextException: Unable to start ServletWebServerApplicationContext due to missing ServletWebServerFactory bean. at org.springframework.boot.web.servlet.context.ServletWebServerApplicationContext.onRefresh(ServletWebServerApplicationContext.java:157) at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:543) at org.springframework.boot.web.servlet.context.ServletWebServerApplicationContext.refresh(ServletWebServerApplicationContext.java:142) at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:775) at org.springframework.boot.SpringApplication.refreshContext(SpringApplication.java:397) at org.springframework.boot.SpringApplication.run(SpringApplication.java:316) at org.springframework.boot.SpringApplication.run(SpringApplication.java:1260) at org.springframework.boot.SpringApplication.run(SpringApplication.java:1248) at com.example.exampleApplication.main(exampleApplication.java:27) Caused by: org.springframework.context.ApplicationContextException: Unable to start ServletWebServerApplicationContext due to missing ServletWebServerFactory bean. at org.springframework.boot.web.servlet.context.ServletWebServerApplicationContext.getWebServerFactory(ServletWebServerApplicationContext.java:206) at org.springframework.boot.web.servlet.context.ServletWebServerApplicationContext.createWebServer(ServletWebServerApplicationContext.java:180) at org.springframework.boot.web.servlet.context.ServletWebServerApplicationContext.onRefresh(ServletWebServerApplicationContext.java:154) ... 8 common frames omitted
該当のソースコード
メインのクラスは下記のとおりです
java
1 2package com.example; 3 4import org.springframework.boot.SpringApplication; 5import org.springframework.boot.autoconfigure.SpringBootApplication; 6import org.springframework.boot.autoconfigure.domain.EntityScan; 7import org.springframework.boot.builder.SpringApplicationBuilder; 8import org.springframework.boot.web.servlet.support.SpringBootServletInitializer; 9 10@SpringBootApplication 11@EntityScan("com.example") 12public class MainApp extends SpringBootServletInitializer { 13 14 @Override 15 protected SpringApplicationBuilder configure(SpringApplicationBuilder application) { 16 return application.sources(MainApp.class); 17 } 18 19 public static void main(String[] args) { 20 SpringApplication.run(MainApp.class, args); 21 } 22 23} 24
build.gradle
buildscript { ext { springBootVersion = '2.1.6.RELEASE' } repositories { mavenCentral() jcenter() maven { url "https://repo.spring.io/release/" } maven { url "https://plugins.gradle.org/m2/" } } dependencies { classpath("org.springframework.boot:spring-boot-gradle-plugin:${springBootVersion}") } } plugins { id 'java' id 'eclipse' id 'org.springframework.boot' version '2.1.6.RELEASE' id 'io.spring.dependency-management' version '1.0.6.RELEASE' id 'jacoco' id 'groovy' id 'com.github.ben-manes.versions' version '0.14.0' id 'com.github.johnrengelman.shadow' version '4.0.2' } apply plugin: 'maven' apply plugin: 'application' sourceCompatibility = '1.8' targetCompatibility = '1.8' wrapper { gradleVersion = "5.4" distributionType = Wrapper.DistributionType.ALL } springBoot { buildInfo() } group = 'com.example' version = '0.1' mainClassName ="com.example.MainApp" defaultTasks 'shadowJar' tasks.withType(JavaCompile) { options.encoding = 'UTF-8' } configurations { compileOnly { extendsFrom annotationProcessor } } repositories { mavenCentral() mavenLocal() } dependencies { implementation 'org.webjars:jquery:3.4.1' implementation 'org.webjars:jquery-ui:1.12.1' implementation 'org.webjars:popper.js:1.15.0' implementation 'org.webjars:bootstrap:4.1.3' implementation 'com.amazonaws:aws-java-sdk:+' implementation 'org.springframework.boot:spring-boot-starter-actuator' implementation 'org.springframework.boot:spring-boot-starter-data-jpa' implementation 'org.springframework.boot:spring-boot-starter-thymeleaf' implementation 'org.springframework.boot:spring-boot-starter-web' // implementation 'org.springframework.boot:spring-boot-starter-security' compileOnly 'org.projectlombok:lombok' runtimeOnly 'org.springframework.boot:spring-boot-devtools' runtimeOnly 'mysql:mysql-connector-java' annotationProcessor 'org.projectlombok:lombok' testImplementation 'org.springframework.boot:spring-boot-starter-test' testImplementation 'org.springframework.security:spring-security-test' } jacoco { toolVersion = "0.8.3" reportsDir = file("$buildDir/customJacocoReportDir") } jacocoTestReport { reports { xml.enabled false csv.enabled false html.destination file("${buildDir}/jacocoHtml") } } shadowJar { mergeServiceFiles() zip64 true exclude 'META-INF/INDEX.LIST' exclude 'META-INF/*.SF' exclude 'META-INF/*.DSA' exclude 'META-INF/*.RSA' } jar{ manifest { attributes "Main-Class" : "com.example.MainApp" } }
試したこと
jarファイルの作成手順として、
対象プロジェクト右クリック-[実行]-[実行構成]-[Gradle Project]より
Gradleタスク "build"
で実行し、jarファイルを作成しております。
下記質問の答えが近いのではと考え、@Beanの手動設定等調べましたが、すべてのソースにおいて問題なく動作しているようです(Eclipse上で問題なく動いていることから、アノテーションが不足しているということは考えにくいと思っています
)
参考質問サイト
補足情報(FW/ツールのバージョンなど)
Eclipse:pleiades
Spring Boot:2.1.6
Gradle:5.2.1
よろしくお願いいたします。
あなたの回答
tips
プレビュー