micronaut-projects / micronaut-core

Micronaut Application Framework
http://micronaut.io
Apache License 2.0
6.04k stars 1.06k forks source link

Datasource name with underscore gets converted to dash #7919

Open kr10n1 opened 2 years ago

kr10n1 commented 2 years ago

Expected Behavior

When I declare a datasource with underscore in it's name it should be created with the same name in Application context

Actual Behaviour

From what I was able to observe at some point the underscore sign gets converted to dash sign but it's not used in this manner universally so application doesn't run properly and fails to find configurations based on this datasource

Steps To Reproduce

Run tests on provided project.

It should fail with error Bean definition [javax.sql.DataSource] could not be loaded: Error instantiating bean of type [javax.sql.DataSource] Message: Driver org.postgresql.Driver claims to not accept jdbcUrl, jdbc:tc:postgresql:12:///zebra

This is because at the point of populating PropertySourcePropertyResolver's catalog map it tries to find driverClassName based on datasource name with dash inside instead of underscore which fails, and driver resolution defaults to Postgresql driver. Screenshot with values populated in debug session image

On the side note: on my original project I was able to run tests further and have them fail at bean resolution due to the same problem with underscore conversion. This is probably due to some library version mismatch. Below I'm posting plugins and dependencies sections for that project if that's of any help

micronautVersion=3.5.2 plugins { id 'com.jfrog.artifactory' version '4.28.4' id "groovy" id "io.micronaut.application" version '3.0.0' id "com.google.cloud.tools.jib" version "3.2.1" id 'java-library' id 'maven-publish' id 'com.github.jk1.dependency-license-report' version '1.17' }

dependencies { annotationProcessor("io.micronaut.data:micronaut-data-processor") annotationProcessor("io.micronaut.openapi:micronaut-openapi:4.3.0") implementation 'io.micronaut:micronaut-management' implementation("io.micronaut:micronaut-validation") implementation("io.micronaut:micronaut-runtime") implementation("io.micronaut:micronaut-http-client") implementation("io.micronaut:micronaut-management") implementation("io.micronaut.sql:micronaut-jdbc-hikari:4.6.0") implementation("io.micronaut.data:micronaut-data-jdbc") implementation("io.micronaut.kubernetes:micronaut-kubernetes-discovery-client") implementation("io.micronaut.liquibase:micronaut-liquibase") implementation("io.micronaut.security:micronaut-security-oauth2") implementation("io.micronaut.security:micronaut-security-jwt") implementation("io.micronaut.rxjava2:micronaut-rxjava2") implementation("io.micronaut.multitenancy:micronaut-multitenancy") implementation("io.projectreactor:reactor-core") implementation("javax.annotation:javax.annotation-api") implementation('io.swagger.core.v3:swagger-annotations:2.2.0') implementation('org.apache.commons:commons-lang3:3.12.0') implementation("org.testcontainers:postgresql") implementation('org.slf4j:jul-to-slf4j:1.7.36') implementation(platform("org.testcontainers:testcontainers-bom:1.17.3")) implementation('com.google.code.gson:gson:2.9.0') implementation('org.jetbrains.kotlin:kotlin-stdlib-wasm:1.7.0') runtimeOnly('org.postgresql:postgresql:42.3.6') runtimeOnly("ch.qos.logback:logback-classic") testImplementation 'org.skyscreamer:jsonassert:1.5.1' testImplementation 'org.codehaus.groovy:groovy-all:3.0.11' testImplementation "io.micronaut.test:micronaut-test-spock" testImplementation("org.spockframework:spock-core") { exclude group: "org.codehaus.groovy", module: "groovy-all" }

Environment Information

OS: Windows 10 JDK: Zulu 11

Example Application

https://github.com/kr10n1/underscore2

Version

3.5.1

dstepanov commented 2 years ago

It looks like we always convert abc_xyz to abc-xyz, I don't think it can be changed in Micronaut 3.

kr10n1 commented 2 years ago

Is this documented anywhere or is it some type of convention that I'm not aware of ? It would be really helpful if this was stated in bold letters in documentation because debugging it took a considerable amount of time.

coulibalyIsmael commented 1 year ago

An alternative is to use io.micronaut.core.convert.format.MapFormat with the attribut setter :

@ConfigurationProperties("test.custom")
public class CustomProperties {
    private Map<String, String> lib;
    public void setLib(@MapFormat(keyFormat= RAW) Map<String, String> lib) { this.lib = lib;}
}