spring.travel.site.Application.java Source code

Java tutorial

Introduction

Here is the source code for spring.travel.site.Application.java

Source

/**
 * Copyright 2014 Andy Godwin
 *
 * 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 spring.travel.site;

import com.fasterxml.jackson.databind.ObjectMapper;
import com.google.common.cache.Cache;
import com.google.common.cache.CacheBuilder;
import com.ning.http.client.AsyncHttpClient;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.PropertySource;
import org.springframework.web.servlet.ViewResolver;
import org.zapodot.jackson.java8.JavaOptionalModule;
import spring.travel.site.auth.Signer;
import spring.travel.site.auth.Verifier;
import spring.travel.site.model.NewsItem;
import spring.travel.site.model.weather.DailyForecast;
import spring.travel.site.services.HttpClient;
import spring.travel.site.view.ConfiguredMustacheViewResolver;

import java.util.List;
import java.util.concurrent.TimeUnit;

@Configuration
@EnableAutoConfiguration
@ComponentScan
@PropertySource("classpath:application.properties")
public class Application {

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

    @Bean
    public Signer signer() {
        return new Signer();
    }

    @Bean
    public Verifier verifier() {
        return new Verifier();
    }

    @Bean
    public AsyncHttpClient asyncHttpClient() {
        return new AsyncHttpClient();
    }

    @Bean
    public ObjectMapper objectMapper() {
        return new ObjectMapper().registerModule(new JavaOptionalModule());
    }

    @Bean
    public HttpClient client() {
        return new HttpClient(objectMapper(), asyncHttpClient());
    }

    @Bean
    public Cache<String, DailyForecast> weatherCache() {
        return CacheBuilder.newBuilder().expireAfterWrite(60, TimeUnit.MINUTES).build();
    }

    @Bean
    public Cache<String, List<NewsItem>> newsCache() {
        return CacheBuilder.newBuilder().expireAfterWrite(60, TimeUnit.MINUTES).build();
    }

    @Bean
    public ViewResolver mustacheViewResolver() {
        return new ConfiguredMustacheViewResolver();
    }

}