io.curly.advisor.AdvisorApplication.java Source code

Java tutorial

Introduction

Here is the source code for io.curly.advisor.AdvisorApplication.java

Source

/*
 *        Copyright 2015 the original author or authors.
 *
 *    Licensed under the Apache License, Version 2.0 (the "License");
 *    you may not use this file except in compliance with the License.
 *    You may obtain a copy of the License at
 *
 *        http://www.apache.org/licenses/LICENSE-2.0
 *
 *    Unless required by applicable law or agreed to in writing, software
 *    distributed under the License is distributed on an "AS IS" BASIS,
 *    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 *    See the License for the specific language governing permissions and
 *    limitations under the License.
 */
package io.curly.advisor;

/**
 * @author Joao Pedro Evangelista
 */

import io.curly.advisor.model.Review;
import io.curly.advisor.model.UserInfo;
import io.curly.commons.config.cache.annotation.EnableRedisCache;
import io.curly.commons.config.context.EnableWorkQueueExecutor;
import io.curly.commons.logging.annotation.config.EnableLoggable;
import org.bson.types.ObjectId;
import org.springframework.boot.CommandLineRunner;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.autoconfigure.reactor.ReactorAutoConfiguration;
import org.springframework.cloud.client.circuitbreaker.EnableCircuitBreaker;
import org.springframework.cloud.client.discovery.EnableDiscoveryClient;
import org.springframework.cloud.netflix.feign.EnableFeignClients;
import org.springframework.context.annotation.Bean;
import org.springframework.dao.DuplicateKeyException;
import org.springframework.data.mongodb.core.MongoTemplate;
import org.springframework.retry.annotation.EnableRetry;

import java.math.BigDecimal;
import java.util.Random;

@EnableRetry
@EnableLoggable
@SpringBootApplication(exclude = { ReactorAutoConfiguration.class })
@EnableDiscoveryClient
@EnableCircuitBreaker
@EnableFeignClients
@EnableRedisCache
@EnableWorkQueueExecutor
public class AdvisorApplication {

    public static void main(String[] args) {
        SpringApplication.run(AdvisorApplication.class, args);
    }

    @Bean
    CommandLineRunner commandLineRunner(MongoTemplate mongoTemplate) {
        return args -> {
            String s = ObjectId.get().toHexString();
            System.out.println("--------------------------------->" + s);
            Review review = new Review("foo", "55b241c6608d54d2de26b891", String.valueOf(new Random(10).nextLong()),
                    "foo", new UserInfo("foo", "url"), BigDecimal.ONE);
            try {
                mongoTemplate.save(review);
            } catch (DuplicateKeyException e) {
                System.out.println(e);
            }
        };
    }

}