Let's say I have a custom starter:
compile ('com.github.hippoom:sms-verification-starter:0.7.0')
You'll have a sms verification feature once you import it to your project. It will provide some beans by convention. The following code snippet in the starter project provides a SmsVerificationCodeSender instance by convention (using @Conditional
and @Bean
).
// the starter project includes the following
public interface SmsVerificationCodeSender {
}
@Configuration
public class ApplicationConfiguration {
@Bean
@ConditionalOnMissingBean(SmsVerificationCodeSender.class)
public SmsVerificationCodeSender smsVerificationCodeSenderStub() {
// setup and return smsVerificationCodeSenderStub instance
}
}
My question is how do I provide http endpoints by convention?
Currently, I make it by using @ComponentScan
// the starter project includes the following as well
//TODO figure out is @ComponentScan is a good practice or not?
@ComponentScan(basePackages = {
"com.thebund1st.daming.web",
})
@Import({
OtherConfiguration.class
})
@Configuration
public class MyAutoConfiguration {
}
package com.thebund1st.daming.web
@RequiredArgsConstructor
@RestController
//TODO make the url path configurable
public class SmsVerificationRestController {
@PostMapping("/api/sms/verification/code")
@ResponseStatus(ACCEPTED)
public void handle(@RequestBody SendSmsVerificationCodeCommand command) {
//omitted codes
}
}
I'm wondering is it the correct way to do this in the starter project?
1) Write a @RestController .
2) Setup a @ComponentScan .
I have this concern just because I don't annotate other beans with @Service/@Repository
, instead I provide the bean instances programmatically by using @Bean
and @Conditional
Besides, it makes it difficult if you want to customize the path of a given @RequestMapping
Here is what I want to achieve:
1) How do a starter provides http endpoints by convention?
2) It should skip the default http endpoints if the user defines his/her own endpoints
3) It should provide some configuration options for the user, like changing URIs etc
You can have a look at this repo if more details are needed.