Skip to content

Provide an easy way to duplicate service AutoConfiguration #35157

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
quaff opened this issue Apr 25, 2023 · 5 comments
Closed

Provide an easy way to duplicate service AutoConfiguration #35157

quaff opened this issue Apr 25, 2023 · 5 comments
Labels
status: duplicate A duplicate of another issue

Comments

@quaff
Copy link
Contributor

quaff commented Apr 25, 2023

It is higher level abstraction of #27834

Currently It's a bit hard to add extra service without back off default one, especially for RedisAutoConfiguration.

Requirement:

  1. keep default service AutoConfiguration in use
  2. duplicate default service with a prefix applied to beanName, configuration properties can be overriden if prefixed configuration key exists
  3. mark default service bean as primary (OPTIONAL)

Possible solution:

Provide a dedicated BeanDefinitionRegistryPostProcessor to duplicate

@RequiredArgsConstructor
public class AutoConfigurationDuplicator implements BeanDefinitionRegistryPostProcessor {

	private final Class<?> autoConfigurationClass;

	private final String prefix;

	private final boolean markDefaultAsPrimary;

	@Override
	public void postProcessBeanFactory(ConfigurableListableBeanFactory beanFactory) throws BeansException {

	}

	@Override
	public void postProcessBeanDefinitionRegistry(BeanDefinitionRegistry registry) throws BeansException {
		// TODO duplicate all BeanDefinitions belong to autoConfigurationClass with
		// prefix, mark default BeanDefinitions as primary if markDefaultAsPrimary is true
	}

}

then duplicate service in application configuration

@Configuration
public class MyConfiguration {

	@Autowired
	@Qualifier("anotherStringRedisTemplate") // anotherStringRedisTemplate is available now
	private StringRedisTemplate anotherStringRedisTemplate; 

	@Bean
	static AutoConfigurationDuplicator anotherRedisConfiguration() {
		return new AutoConfigurationDuplicator(RedisAutoConfiguration.class, "another", false);
	}

}
spring.data.redis:
  host: redis.svc.default.cluster.local
  database: 1

another.spring.data.redis:
#  host: redis.svc.default.cluster.local default to spring.data.redis
  database: 2
@spring-projects-issues spring-projects-issues added the status: waiting-for-triage An issue we've not yet triaged label Apr 25, 2023
@wilkinsona
Copy link
Member

Unfortunately, the comment made on #27834 applies here too:

This is a general problem with our current design and something that we hope to address more holistically with #21322. I don’t think we’ll be able to tackle the problem in a piecemeal fashion without making things worse. We’d rather keep our existing approach of requiring manual configuration if multiple services are being used until we can find a good general purpose solution.

In other words, this is a duplicate of #21322.

@wilkinsona wilkinsona closed this as not planned Won't fix, can't repro, duplicate, stale Apr 25, 2023
@wilkinsona wilkinsona added status: duplicate A duplicate of another issue and removed status: waiting-for-triage An issue we've not yet triaged labels Apr 25, 2023
@quaff
Copy link
Contributor Author

quaff commented Apr 25, 2023

#21322

Does #21322 require kubernetes?

@wilkinsona
Copy link
Member

No. We expect that it will be particularly useful in a Kubernetes environment but I doubt that it will be required.

@quaff
Copy link
Contributor Author

quaff commented Apr 25, 2023

If #21322 is dedicated for that spec, I suggest keep this open, most people want to keep configuration properties in traditional way like this:

spring.data.redis:
  host: redis.svc.default.cluster.local
  database: 1

another.spring.data.redis:
#  host: redis.svc.default.cluster.local default to spring.data.redis
  database: 2

instead of

$SERVICE_BINDING_ROOT
├── account-database
│   ├── type
│   ├── provider
│   ├── uri
│   ├── username
│   └── password
└── transaction-event-stream
    ├── type
    ├── connection-count
    ├── uri
    ├── certificates
    └── private-key

@wilkinsona
Copy link
Member

I don't think there's any need to do that. In addition to #21322, we also have #22403 among others. Please rest assured that this sort of functionality is on our radar.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
status: duplicate A duplicate of another issue
Projects
None yet
Development

No branches or pull requests

3 participants