About

На ΠΌΠΎΠ΅ΠΌ Github ΠΌΠΎΠΆΠ½ΠΎ Π½Π°ΠΉΡ‚ΠΈ малСнькиС ΠΏΡ€ΠΈΠΌΠ΅Ρ€Ρ‹ ΠΏΡ€ΠΈΠ»ΠΎΠΆΠ΅Π½ΠΈΠΉ Π½Π° Spring Framework.

Spring: https://spring.io/ Tutorial: https://kotlinlang.org/docs/jvm-spring-boot-restful.html

ΠŸΡ€ΠΈΠΌΠ΅Ρ€Π½Π°Ρ Π·Π°Π²ΠΈΡΠΈΠΌΠΎΡΡ‚ΡŒ ΠΊΠΎΠΌΠΏΠΎΠ½Π΅Π½Ρ‚ΠΎΠ²:

Configurator β€” ΠΈΠ½ΠΈΡ†ΠΈΠ°Π»ΠΈΠ·ΠΈΡ€ΡƒΠ΅Ρ‚ HttpClient, Service, Controller, ...
Controller β€” ΠΏΡ€ΠΈΠ½ΠΈΠΌΠ°Π΅Ρ‚ Service, ΠΎΠ±Ρ€Π°Π±Π°Ρ‚Ρ‹Π²Π°Π΅Ρ‚ API Π²Ρ‹Π·ΠΎΠ²Ρ‹ ΠΈ ΠΏΠ΅Ρ€Π΅Π΄Π°Π΅Ρ‚ сСрвису
Service β€” ΡƒΡ€ΠΎΠ²Π΅Π½ΡŒ Π»ΠΎΠ³ΠΈΠΊΠΈ, Π±Π΅Ρ€Π΅Ρ‚ Π½Π° сСбя таски Π² Ρ„ΠΎΠ½Π΅

Π’ ΠΊΠΎΠ΄Π΅

Configurator

// ...

@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();
    }
}

// ...

Controller

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);
        // ...
    }

}

Service

Interface

public interface SomeService {

    SomeResult someAction(String postParam);

}

Impl

public class ConnectorSendSmsServiceImpl implements ConnectorSendSmsService {

    // ...
    
}

Last updated