package com.tax.token.job;

import lombok.extern.slf4j.Slf4j;
import org.h2.tools.Server;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.web.client.RestTemplateBuilder;
import org.springframework.cloud.netflix.eureka.EnableEurekaClient;
import org.springframework.cloud.netflix.feign.EnableFeignClients;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.scheduling.annotation.EnableAsync;
import org.springframework.test.context.TestPropertySource;
import org.springframework.web.client.RestTemplate;

import java.sql.SQLException;

/**
 * 
 * ClassName: StartupApplication <br/>
 * Function: springboot启动类，自动加载启动配置,注册服务. <br/>
 * date: 2017年11月7日 下午2:52:59 <br/>
 * @SpringBootApplication 服务启动注解<br/>
 * @EnableEurekaClient EnableEurekaClient注解将本系统所有controller的服务注册到Eureka注册中心<br/>
 * 注册地址通过启动配置项进行设置 eureka.client.serviceUrl.defaultZone<br/>
 * 服务注册名通过启动配置项进行设置 spring.application.name=service-acceptance-demo
 * @ComponentScan 注解会自动扫描子工程下的Bean,包括引入的jar包
 * 
 * @author wuyuegang
 * @version
 * @since JDK 1.8
 */
@Slf4j
@SpringBootApplication
@EnableEurekaClient
@EnableAsync
@EnableFeignClients(basePackages = {"com.tax.token.integration"}) // 开启Feign支持
@ComponentScan(basePackages = {"com.tax.token"})
public class TokenStartupApplication
{
    
	// 启动的时候要注意，由于我们在controller中注入了RestTemplate，所以启动的时候需要实例化该类的一个实例 
    @Autowired 
    private RestTemplateBuilder builder; 
   
    // 使用RestTemplateBuilder来实例化RestTemplate对象，spring默认已经注入了RestTemplateBuilder实例 
    @Bean 
    public RestTemplate restTemplate() { 
        return builder.build(); 
    }


//    @Bean
//    public NioWebSocketClient webSocketClient(){
//        return new NioWebSocketClient();
//    }

    public static void main(String[] args) throws SQLException {
        EmbedZookeeperServer.start(6181);
        Server.createTcpServer("-tcpPort", String.valueOf(9092), "-tcpPassword", "sa", "-ifNotExists", "-tcpAllowOthers").start();
        log.info("start h2 server success");
        SpringApplication.run(TokenStartupApplication.class, args);
    }
}
