Примерная зависимость компонентов:
Copy Configurator — инициализирует HttpClient, Service, Controller, ...
Controller — принимает Service, обрабатывает API вызовы и передает сервису
Service — уровень логики, берет на себя таски в фоне
Copy // ...
@ Configurator
public class SomeContextConfigurator {
@ Bean
public SomeController someController ( ... ) {
return new SomeController(someService , ... ) ;
}
@ Bean
public SomeService someService (
...
) {
return new SomeService( ... ) ;
}
@ Bean
public CloseableHttpClient httpClient (
...
) {
ApacheHttpClientUtils . Builder builder = ApacheHttpClientUtils . Builder . create ()
. multiThreaded ()
. // ...
return builder . build ();
}
}
// ...
Copy import org . springframework . web . bind . annotation . RequestMapping ;
import org . springframework . web . bind . annotation . RequestMethod ;
import org . springframework . web . bind . annotation . RequestParam ;
import org . springframework . web . bind . annotation . RestController ;
@ RestController
@ RequestMapping (value = "/some" )
public class SomeController {
private final SomeService someService;
public SomeController (
SomeService someService
) {
this . someService = someService;
}
@ RequestMapping (value = "send" , method = RequestMethod . POST )
public SomeResult someAction (
@ RequestParam ( "post_param" ) String postParam
) {
// ...
someService . someAction (postParam);
// ...
}
}
Copy public interface SomeService {
SomeResult someAction ( String postParam);
}
Copy public class ConnectorSendSmsServiceImpl implements ConnectorSendSmsService {
// ...
}