Skip to content

Annotations like @Ssl don't work on @Bean methods when using @ServiceConnection #50011

@mhalbritter

Description

@mhalbritter

Given this configuration:

@TestConfiguration(proxyBeanMethods = false)
class TestcontainersConfiguration {

	@Bean
	@ServiceConnection
	@Ssl
	ElasticsearchContainer elasticsearchContainer() {
		return new ElasticsearchContainer(DockerImageName.parse("docker.elastic.co/elasticsearch/elasticsearch:9.3.3"));
	}

}

the code in
org.springframework.boot.elasticsearch.testcontainers.ElasticsearchContainerConnectionDetailsFactory.ElasticsearchContainerConnectionDetails#getSslBundle:

if (hasAnnotation(Ssl.class)) {

returns false. No annotations are detected. It works when defining the container as a field:

public interface MyContainers {
    @Container
    @ServiceConnection
    @Ssl
    ElasticsearchContainer elasticsearchContainer = new ElasticsearchContainer(DockerImageName.parse("docker.elastic.co/elasticsearch/elasticsearch:9.3.3"));
}
@TestConfiguration(proxyBeanMethods = false)
@ImportTestcontainers(MyContainers.class)
class TestcontainersConfiguration {

}

Reproducer: Archive.zip

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions