Last active
April 27, 2017 19:11
-
-
Save sidneydemoraes/a4712ef8411cb246a9cffced6b049312 to your computer and use it in GitHub Desktop.
TechTalk - Gradle + Spring Boot + Groovy - Application.groovy (Web Application)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import br.com.smc.meurumo.config.ConfigProperties | |
import com.paypal.base.rest.APIContext | |
import org.springframework.beans.factory.annotation.Autowired | |
import org.springframework.boot.SpringApplication | |
import org.springframework.boot.autoconfigure.SpringBootApplication | |
import org.springframework.boot.context.embedded.ConfigurableEmbeddedServletContainer | |
import org.springframework.boot.context.embedded.EmbeddedServletContainerCustomizer | |
import org.springframework.boot.web.servlet.ErrorPage | |
import org.springframework.context.annotation.Bean | |
import org.springframework.http.HttpStatus | |
import java.util.concurrent.ExecutorService | |
import java.util.concurrent.Executors | |
/** | |
* Classe de inicialização do Spring Boot. | |
*/ | |
@SpringBootApplication | |
class Application { | |
/** | |
* Método de inicialização. | |
* @param args | |
*/ | |
public static void main(String[] args) { | |
SpringApplication.run(Application.class, args) | |
} | |
/** | |
* Configuração global para tratamento de erros HTTP e redirecionamento para a página apropriada. | |
*/ | |
@Bean | |
EmbeddedServletContainerCustomizer containerCustomizer() { | |
return new EmbeddedServletContainerCustomizer() { | |
@Override | |
public void customize(ConfigurableEmbeddedServletContainer container) { | |
ErrorPage error404Page = new ErrorPage(HttpStatus.NOT_FOUND, "/error/404") | |
ErrorPage error405Page = new ErrorPage(HttpStatus.METHOD_NOT_ALLOWED, "/error/404") | |
ErrorPage globalErrorPage = new ErrorPage("/error/500") | |
container.addErrorPages(error404Page) | |
container.addErrorPages(error405Page) | |
container.addErrorPages(globalErrorPage) | |
} | |
}; | |
} | |
/** | |
* Executor responsável por gerenciar as threads usadas no paralelismo da aplicaçao. | |
* @return | |
*/ | |
@Bean | |
ExecutorService threadExecutorService() { | |
ExecutorService executor = Executors.newFixedThreadPool(10) | |
return executor | |
} | |
/** | |
* Componente configurado do Paypal para efetuar os fluxos transacionais de pagamento. | |
* @return | |
*/ | |
@Bean | |
APIContext paypalApiContext() { | |
APIContext context = new APIContext(config.paypalClientId , config.paypalClientSecret, config.paypalEnvironment); | |
return context | |
} | |
/* Componentes injetados */ | |
@Autowired | |
ConfigProperties config | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment