0

убрали лишнюю spring-конфигурацию

This commit is contained in:
2017-12-25 00:57:42 +03:00
parent 0f92e3171c
commit 41b3844ec8
6 changed files with 20 additions and 42 deletions

View File

@@ -1,31 +0,0 @@
/*
* DmitriyMX <dmitriymx@yandex.ru>
* 2017-01-04
*/
package kinosearch.core;
import com.google.gson.Gson;
import com.google.gson.GsonBuilder;
import kinosearch.core.browser.ApacheHttpBrowser;
import kinosearch.core.browser.Browser;
import kinosearch.webapp.KinoPlaySerializer;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Scope;
@Configuration
@ComponentScan(basePackages = {"kinosearch.core.browser", "kinosearch.core.warez"})
public class SpringConfig {
@Bean
@Scope("prototype")
public Browser browser() {
return new ApacheHttpBrowser();
}
@Bean
@Scope("singleton")
public Gson gson() {
return new GsonBuilder().registerTypeAdapter(KinoPlay.class, new KinoPlaySerializer()).create();
}
}

View File

@@ -13,6 +13,8 @@ import org.apache.http.client.methods.HttpPost;
import org.apache.http.entity.StringEntity; import org.apache.http.entity.StringEntity;
import org.apache.http.impl.client.HttpClients; import org.apache.http.impl.client.HttpClients;
import org.apache.http.message.BasicHeader; import org.apache.http.message.BasicHeader;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Component;
import java.io.BufferedReader; import java.io.BufferedReader;
import java.io.IOException; import java.io.IOException;
@@ -21,6 +23,8 @@ import java.io.InputStreamReader;
import java.util.HashSet; import java.util.HashSet;
import java.util.Set; import java.util.Set;
@Component("browser")
@Scope("prototype")
public class ApacheHttpBrowser implements Browser { public class ApacheHttpBrowser implements Browser {
private Set<Header> headers = new HashSet<>(); private Set<Header> headers = new HashSet<>();
private String encoding = "UTF-8"; private String encoding = "UTF-8";

View File

@@ -4,19 +4,25 @@
*/ */
package kinosearch.webapp; package kinosearch.webapp;
import com.google.gson.Gson;
import com.google.gson.GsonBuilder;
import kinosearch.core.KinoPlay;
import org.springframework.beans.factory.annotation.Value; import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.*;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Import;
import org.springframework.context.annotation.PropertySource;
import org.springframework.web.servlet.ViewResolver; import org.springframework.web.servlet.ViewResolver;
import org.springframework.web.servlet.view.freemarker.FreeMarkerConfigurer; import org.springframework.web.servlet.view.freemarker.FreeMarkerConfigurer;
import org.springframework.web.servlet.view.freemarker.FreeMarkerViewResolver; import org.springframework.web.servlet.view.freemarker.FreeMarkerViewResolver;
@Configuration @Configuration
@Import(kinosearch.core.SpringConfig.class) @ComponentScan(basePackages = {"kinosearch.core.browser", "kinosearch.core.warez"})
@PropertySource("classpath:/application.properties") @PropertySource("classpath:/application.properties")
public class SpringConfig { public class SpringConfig {
@Bean
@Scope("singleton")
public Gson gson() {
return new GsonBuilder().registerTypeAdapter(KinoPlay.class, new KinoPlaySerializer()).create();
}
@Bean @Bean
public WebApp webapp(@Value("${webapp.host}") String host, @Value("${webapp.port}") int port) { public WebApp webapp(@Value("${webapp.host}") String host, @Value("${webapp.port}") int port) {
return new WebApp(host, port); return new WebApp(host, port);

View File

@@ -2,9 +2,7 @@ package kinosearch.core.browser;
import com.google.gson.Gson; import com.google.gson.Gson;
import com.google.gson.JsonObject; import com.google.gson.JsonObject;
import kinosearch.core.SpringConfig; import kinosearch.webapp.SpringConfig;
import kinosearch.core.browser.Browser;
import static org.junit.Assert.*;
import org.junit.Test; import org.junit.Test;
import org.junit.runner.RunWith; import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
@@ -13,6 +11,8 @@ import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
import java.io.IOException; import java.io.IOException;
import static org.junit.Assert.assertEquals;
@RunWith(SpringJUnit4ClassRunner.class) @RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration(classes = {SpringConfig.class}) @ContextConfiguration(classes = {SpringConfig.class})
public class TestBrowser { public class TestBrowser {

View File

@@ -4,8 +4,7 @@
*/ */
package kinosearch.core.warez; package kinosearch.core.warez;
import kinosearch.core.KinoPlay; import kinosearch.webapp.SpringConfig;
import kinosearch.core.SpringConfig;
import org.junit.Test; import org.junit.Test;
import org.junit.runner.RunWith; import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;

View File

@@ -4,7 +4,7 @@
*/ */
package kinosearch.core.warez; package kinosearch.core.warez;
import kinosearch.core.SpringConfig; import kinosearch.webapp.SpringConfig;
import org.junit.Test; import org.junit.Test;
import org.junit.runner.RunWith; import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;