実現したいこと
mavenで実行可能jarを作成したい。
発生している問題・分からないこと
OS: Windows
SpringBoot 3.2.0
Java 21
Tomcat 10.1.10
maven 3.9.5
SpringBoot で作成したプロジェクトを maven の以下のコマンドで実行可能jarにしようとしたところ、NullPointerExceptionで失敗します。
mvn clean package -X spring-boot:repackage
本プロジェクトは元々 SpringBoot 2.6.7 で運用しており、その時は上述のコマンドで実行可能jarにできていたのですが、3.2.0へバージョンアップ以降にエラーが出るようになりました。バージョンの移行にて実施したのは pom.xmlの変更(SptinBoot,Java,Tomcat,依存ライブラリのバージョン変更)、javaxをjakartaに変更、SpringSecurity関係の記述を最新化です。
なお、Eclipse上でアプリケーションを実行するとエラーは出ず、正常に起動できます。
TestProperties.java は@PropertySourceでyamlファイルを読み込んでおり、それ関係の記述を当たってみたのですが原因がわかりませんでした。test.ymlは src/main/resources に配置しています。
エラーメッセージ
error
1[INFO] Compiling 245 source files with javac [debug release 21] to target\classes 2[INFO] ------------------------------------------------------------------------ 3[INFO] BUILD FAILURE 4[INFO] ------------------------------------------------------------------------ 5[ERROR] Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:3.11.0:compile (default-compile) on project ***project: Fatal error compiling: java.lang.IllegalStateException: Error processing configuration meta-data on com.***project.infrastructure.repositories.custom.TestProperties: NullPointerException -> [Help 1] 6org.apache.maven.lifecycle.LifecycleExecutionException: Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:3.11.0:compile (default-compile) on project ***project: Fatal error compiling 7 at org.apache.maven.lifecycle.internal.MojoExecutor.doExecute2 (MojoExecutor.java:333) 8 at org.apache.maven.lifecycle.internal.MojoExecutor.doExecute (MojoExecutor.java:316) 9(省略) 10Caused by: java.lang.IllegalStateException: Error processing configuration meta-data on com.***project.infrastructure.repositories.custom.TestProperties 11 at org.springframework.boot.configurationprocessor.ConfigurationMetadataAnnotationProcessor.processElement (ConfigurationMetadataAnnotationProcessor.java:226) 12 at org.springframework.boot.configurationprocessor.ConfigurationMetadataAnnotationProcessor.process (ConfigurationMetadataAnnotationProcessor.java:180) 13(省略) 14Caused by: java.lang.NullPointerException 15 at java.util.Objects.requireNonNull (Objects.java:233) 16 at java.util.Optional.of (Optional.java:113) 17(省略) 18 19[Help 1] http://cwiki.apache.org/confluence/display/MAVEN/MojoExecutionException
該当のソースコード
Java
1TestProperties.java 2 3package com.***project.infrastructure.repositories.custom; 4 5import org.springframework.beans.factory.annotation.Value; 6import org.springframework.boot.context.properties.ConfigurationProperties; 7import org.springframework.context.annotation.Configuration; 8import org.springframework.context.annotation.PropertySource; 9 10import lombok.Getter; 11 12@Getter 13@Configuration 14@ConfigurationProperties(prefix = "") 15@PropertySource(value = "file:test.yml", factory = TestPropertySourceFactory.class) 16public class CustomYamlProperties { 17 18 /** サブシステムURL **/ 19 @Value("${url}") 20 private String subSystemUrl; 21 22 /** 以下、複数プロパティ **/ 23 24}
Java
1package com.***project.infrastructure.repositories.custom; 2 3import java.io.IOException; 4import java.util.Properties; 5 6import org.springframework.beans.factory.config.TestPropertiesFactoryBean; 7import org.springframework.core.env.PropertiesPropertySource; 8import org.springframework.core.env.PropertySource; 9import org.springframework.core.io.support.EncodedResource; 10import org.springframework.core.io.support.PropertySourceFactory; 11 12/** 13 */ 14public class TestPropertySourceFactory implements PropertySourceFactory { 15 16 @Override 17 public PropertySource<?> createPropertySource(String name, EncodedResource encodedResource) 18 throws IOException { 19 TestPropertiesFactoryBean factory = new TestPropertiesFactoryBean(); 20 factory.setResources(encodedResource.getResource()); 21 22 Properties properties = factory.getObject(); 23 24 return new PropertiesPropertySource(encodedResource.getResource().getFilename(), properties); 25 } 26}
xml
1pom.xml 2 3 <plugin> 4 <groupId>org.apache.maven.plugins</groupId> 5 <artifactId>maven-antrun-plugin</artifactId> 6 <executions> 7 <execution> 8 <phase>prepare-package</phase> 9 <goals> 10 <goal>run</goal> 11 </goals> 12 <configuration> 13 <target> 14 <delete> 15 <fileset dir="${project.build.outputDirectory}" 16 includes="test.yml" /> 17 </delete> 18 </target> 19 </configuration> 20 </execution> 21 </executions> 22 </plugin>
試したこと・調べたこと
- teratailやGoogle等で検索した
- ソースコードを自分なりに変更した
- 知人に聞いた
- その他
上記の詳細・結果
pom.xmlにてtest.ymlを実行可能jarに取り込まないように設定しているため、該当部分を削除して実行してみましたが結果は変わりませんでした。
補足
情報不足等あれば教えて頂けますでしょうか。
あなたの回答
tips
プレビュー