質問をすることでしか得られない、回答やアドバイスがある。

15分調べてもわからないことは、質問しよう!

新規登録して質問してみよう
ただいま回答率
85.50%
Java

Javaは、1995年にサン・マイクロシステムズが開発したプログラミング言語です。表記法はC言語に似ていますが、既存のプログラミング言語の短所を踏まえていちから設計されており、最初からオブジェクト指向性を備えてデザインされています。セキュリティ面が強力であることや、ネットワーク環境での利用に向いていることが特徴です。Javaで作られたソフトウェアは基本的にいかなるプラットフォームでも作動します。

Q&A

解決済

1回答

1201閲覧

Quarkusアプリケーションで@ConfigPropertyが有効にならずnull

yurak

総合スコア160

Java

Javaは、1995年にサン・マイクロシステムズが開発したプログラミング言語です。表記法はC言語に似ていますが、既存のプログラミング言語の短所を踏まえていちから設計されており、最初からオブジェクト指向性を備えてデザインされています。セキュリティ面が強力であることや、ネットワーク環境での利用に向いていることが特徴です。Javaで作られたソフトウェアは基本的にいかなるプラットフォームでも作動します。

0グッド

0クリップ

投稿2020/01/22 16:22

編集2020/01/22 16:27

Quarkusアプリケーションで@ConfigPropertyが有効ならない

Quarkusではapplication.propertiesに記載したkey=valueの値を、
@ConfigPropertyを指定することで取得できるが、実行するとnullが返ってくる。

発生している問題・エラーメッセージ

git/k8s-3tier-webapp-minikube/application/redis-mysql-quarkus % ./mvnw compile quarkus:dev [INFO] Scanning for projects... [INFO] [INFO] --------------------< org.acme:redis-mysql-quarkus >-------------------- [INFO] Building redis-mysql-quarkus 1.0.0-SNAPSHOT [INFO] --------------------------------[ jar ]--------------------------------- [INFO] [INFO] --- maven-resources-plugin:2.6:resources (default-resources) @ redis-mysql-quarkus --- [INFO] Using 'UTF-8' encoding to copy filtered resources. [INFO] Copying 3 resources [INFO] [INFO] --- maven-compiler-plugin:3.8.1:compile (default-compile) @ redis-mysql-quarkus --- [INFO] Nothing to compile - all classes are up to date [INFO] [INFO] --- quarkus-maven-plugin:1.0.1.Final:dev (default-cli) @ redis-mysql-quarkus --- Listening for transport dt_socket at address: 5005 The application is starting... 2019-12-20 17:17:49,727 INFO [io.quarkus] (main) Quarkus 1.0.1.Final started in 0.956s. Listening on: http://0.0.0.0:8080 2019-12-20 17:17:49,785 INFO [io.quarkus] (main) Profile dev activated. Live Coding activated. 2019-12-20 17:17:49,785 INFO [io.quarkus] (main) Installed features: [cdi, jdbc-mysql, resteasy] java.lang.IllegalArgumentException: hostname can't be null at java.net.InetSocketAddress.checkHost(InetSocketAddress.java:149) at java.net.InetSocketAddress.<init>(InetSocketAddress.java:216) at redis.clients.jedis.Connection.connect(Connection.java:181) at redis.clients.jedis.BinaryClient.connect(BinaryClient.java:100) at redis.clients.jedis.Connection.setTimeoutInfinite(Connection.java:93) at redis.clients.jedis.Jedis.subscribe(Jedis.java:2787) at org.acme.service.RedisService.subscribeRedis(RedisService.java:39) at org.acme.events.TaskExecute.run(TaskExecute.java:13) at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149) at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624) at java.lang.Thread.run(Thread.java:748) the application is stopping...

該当のソースコード

https://github.com/yurake/k8s-3tier-webapp/blob/master/application/redis-mysql-quarkus/src/main/java/org/acme/service/RedisService.java
※ ResourceBundle.getBundleで代替中

java

1package org.acme.service; 2 3import java.sql.Connection; 4import java.util.logging.Logger; 5 6import javax.inject.Inject; 7import javax.ws.rs.ext.Provider; 8 9import org.eclipse.microprofile.config.inject.ConfigProperty; 10 11import redis.clients.jedis.Jedis; 12import redis.clients.jedis.JedisPubSub; 13import redis.clients.jedis.exceptions.JedisConnectionException; 14 15@Provider 16public class RedisService { 17 18 Connection con = null; 19 20 private static final Logger LOG = Logger.getLogger(RedisService.class.getSimpleName()); 21// private static String servername = GetConfig.getResourceBundle("redis.server"); 22// private static int serverport = Integer.parseInt(GetConfig.getResourceBundle("redis.port")); 23// private static String channel = GetConfig.getResourceBundle("redis.channel"); 24// private static String splitkey = GetConfig.getResourceBundle("redis.splitkey"); 25 26 @Inject 27 @ConfigProperty(name = "redis.server") 28 String servername; 29 30 @Inject 31 @ConfigProperty(name = "redis.port") 32 int serverport; 33 34 @Inject 35 @ConfigProperty(name = "redis.channel") 36 String channel; 37 38 @Inject 39 @ConfigProperty(name = "redis.splitkey") 40 String splitkey; 41 42 public boolean ping() { 43 Jedis jedis = new Jedis(servername, serverport); 44 try { 45 if (jedis.ping().equalsIgnoreCase("PONG")) { 46 return true; 47 } 48 } catch (JedisConnectionException e) { 49 e.printStackTrace(); 50 } finally { 51 jedis.close(); 52 } 53 return false; 54 } 55 56 public void subscribeRedis() { 57 58 MysqlService mysqlsvc = new MysqlService(); 59 Jedis jedis = new Jedis(servername, serverport); 60 try { 61 jedis.subscribe(new JedisPubSub() { 62 @Override 63 public void onMessage(String channel, String message) { 64 String fullmsg = null; 65 String[] body = message.split(splitkey, 0); 66 fullmsg = "Received channel:" + channel + ", id: " + body[0]+ ", msg: " + body[1]; 67 LOG.info(fullmsg); 68 mysqlsvc.insertMysql(body); 69 } 70 }, channel); 71 } catch (Exception e) { 72 e.printStackTrace(); 73 } finally { 74 jedis.close(); 75 } 76 } 77} 78

properties

1# Configuration file 2# key = value 3 4# Redis Client 5redis.server = redis 6redis.port = 6379 7redis.channel = pubsub 8redis.splitkey = ,

試したこと

https://quarkus.io/guides/config
で記載されている内容は一通り実施済み。

補足情報(FW/ツールのバージョンなど)

pom.xml

xml

1<?xml version="1.0"?> 2<project xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd" xmlns="http://maven.apache.org/POM/4.0.0" 3 xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"> 4 <modelVersion>4.0.0</modelVersion> 5 <groupId>webapp.3tier.k8s</groupId> 6 <artifactId>redis-mysql-quarkus</artifactId> 7 <version>1.0.0-SNAPSHOT</version> 8 <properties> 9 <compiler-plugin.version>3.8.1</compiler-plugin.version> 10 <maven.compiler.parameters>true</maven.compiler.parameters> 11 <maven.compiler.source>1.8</maven.compiler.source> 12 <maven.compiler.target>1.8</maven.compiler.target> 13 <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> 14 <project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding> 15 <quarkus-plugin.version>1.0.1.Final</quarkus-plugin.version> 16 <quarkus.platform.artifact-id>quarkus-universe-bom</quarkus.platform.artifact-id> 17 <quarkus.platform.group-id>io.quarkus</quarkus.platform.group-id> 18 <quarkus.platform.version>1.0.1.Final</quarkus.platform.version> 19 <surefire-plugin.version>2.22.1</surefire-plugin.version> 20 <jedis.version>3.1.0</jedis.version> 21 </properties> 22 <dependencyManagement> 23 <dependencies> 24 <dependency> 25 <groupId>${quarkus.platform.group-id}</groupId> 26 <artifactId>${quarkus.platform.artifact-id}</artifactId> 27 <version>${quarkus.platform.version}</version> 28 <type>pom</type> 29 <scope>import</scope> 30 </dependency> 31 </dependencies> 32 </dependencyManagement> 33 <dependencies> 34 <dependency> 35 <groupId>io.quarkus</groupId> 36 <artifactId>quarkus-resteasy</artifactId> 37 </dependency> 38 <dependency> 39 <groupId>io.quarkus</groupId> 40 <artifactId>quarkus-junit5</artifactId> 41 <scope>test</scope> 42 </dependency> 43 <dependency> 44 <groupId>io.rest-assured</groupId> 45 <artifactId>rest-assured</artifactId> 46 <scope>test</scope> 47 </dependency> 48 <dependency> 49 <groupId>io.quarkus</groupId> 50 <artifactId>quarkus-jdbc-mysql</artifactId> 51 </dependency> 52 <dependency> 53 <groupId>io.quarkus</groupId> 54 <artifactId>quarkus-smallrye-health</artifactId> 55 </dependency> 56 <dependency> 57 <groupId>redis.clients</groupId> 58 <artifactId>jedis</artifactId> 59 <version>${jedis.version}</version> 60 </dependency> 61 </dependencies> 62 <build> 63 <plugins> 64 <plugin> 65 <groupId>io.quarkus</groupId> 66 <artifactId>quarkus-maven-plugin</artifactId> 67 <version>${quarkus-plugin.version}</version> 68 <executions> 69 <execution> 70 <goals> 71 <goal>build</goal> 72 </goals> 73 </execution> 74 </executions> 75 </plugin> 76 <plugin> 77 <artifactId>maven-compiler-plugin</artifactId> 78 <version>${compiler-plugin.version}</version> 79 </plugin> 80 <plugin> 81 <artifactId>maven-surefire-plugin</artifactId> 82 <version>${surefire-plugin.version}</version> 83 <configuration> 84 <systemProperties> 85 <java.util.logging.manager>org.jboss.logmanager.LogManager</java.util.logging.manager> 86 </systemProperties> 87 </configuration> 88 </plugin> 89 </plugins> 90 </build> 91 <profiles> 92 <profile> 93 <id>native</id> 94 <activation> 95 <property> 96 <name>native</name> 97 </property> 98 </activation> 99 <build> 100 <plugins> 101 <plugin> 102 <artifactId>maven-failsafe-plugin</artifactId> 103 <version>${surefire-plugin.version}</version> 104 <executions> 105 <execution> 106 <goals> 107 <goal>integration-test</goal> 108 <goal>verify</goal> 109 </goals> 110 <configuration> 111 <systemProperties> 112 <native.image.path>${project.build.directory}/${project.build.finalName}-runner</native.image.path> 113 </systemProperties> 114 </configuration> 115 </execution> 116 </executions> 117 </plugin> 118 </plugins> 119 </build> 120 <properties> 121 <quarkus.package.type>native</quarkus.package.type> 122 </properties> 123 </profile> 124 </profiles> 125</project> 126

https://github.com/yurake/k8s-3tier-webapp/issues/1

気になる質問をクリップする

クリップした質問は、後からいつでもMYページで確認できます。

またクリップした質問に回答があった際、通知やメールを受け取ることができます。

バッドをするには、ログインかつ

こちらの条件を満たす必要があります。

guest

回答1

0

自己解決

MongodbService.java

1@ApplicationScoped 2@Provider 3public class MongodbService implements Database {

投稿2020/05/24 08:12

yurak

総合スコア160

バッドをするには、ログインかつ

こちらの条件を満たす必要があります。

あなたの回答

tips

太字

斜体

打ち消し線

見出し

引用テキストの挿入

コードの挿入

リンクの挿入

リストの挿入

番号リストの挿入

表の挿入

水平線の挿入

プレビュー

15分調べてもわからないことは
teratailで質問しよう!

ただいまの回答率
85.50%

質問をまとめることで
思考を整理して素早く解決

テンプレート機能で
簡単に質問をまとめる

質問する

関連した質問