перемещаем SpringConfig, бины viewResolver и freemarkerConfig
This commit is contained in:
28
src/main/java/kinosearch/core/SpringConfig.java
Normal file
28
src/main/java/kinosearch/core/SpringConfig.java
Normal file
@@ -0,0 +1,28 @@
|
||||
/*
|
||||
* DmitriyMX <dmitriymx@yandex.ru>
|
||||
* 2017-12-11
|
||||
*/
|
||||
package kinosearch.core;
|
||||
|
||||
import com.google.gson.Gson;
|
||||
import com.google.gson.GsonBuilder;
|
||||
import kinosearch.webapp.KinoPlaySerializer;
|
||||
import kinosearch.webapp.WebApp;
|
||||
import org.springframework.beans.factory.annotation.Value;
|
||||
import org.springframework.context.annotation.*;
|
||||
|
||||
@Configuration
|
||||
@ComponentScan(basePackages = {"kinosearch.core.browser", "kinosearch.core.warez"})
|
||||
@PropertySource("classpath:/application.properties")
|
||||
public class SpringConfig {
|
||||
@Bean
|
||||
@Scope("singleton")
|
||||
public Gson gson() {
|
||||
return new GsonBuilder().registerTypeAdapter(KinoPlay.class, new KinoPlaySerializer()).create();
|
||||
}
|
||||
|
||||
@Bean
|
||||
public WebApp webapp(@Value("${webapp.host}") String host, @Value("${webapp.port}") int port) {
|
||||
return new WebApp(host, port);
|
||||
}
|
||||
}
|
||||
@@ -4,6 +4,7 @@
|
||||
*/
|
||||
package kinosearch.webapp;
|
||||
|
||||
import kinosearch.core.SpringConfig;
|
||||
import org.springframework.context.ApplicationContext;
|
||||
import org.springframework.context.annotation.AnnotationConfigApplicationContext;
|
||||
|
||||
|
||||
@@ -1,46 +0,0 @@
|
||||
/*
|
||||
* DmitriyMX <dmitriymx@yandex.ru>
|
||||
* 2017-12-11
|
||||
*/
|
||||
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.context.annotation.*;
|
||||
import org.springframework.web.servlet.ViewResolver;
|
||||
import org.springframework.web.servlet.view.freemarker.FreeMarkerConfigurer;
|
||||
import org.springframework.web.servlet.view.freemarker.FreeMarkerViewResolver;
|
||||
|
||||
@Configuration
|
||||
@ComponentScan(basePackages = {"kinosearch.core.browser", "kinosearch.core.warez"})
|
||||
@PropertySource("classpath:/application.properties")
|
||||
public class SpringConfig {
|
||||
@Bean
|
||||
@Scope("singleton")
|
||||
public Gson gson() {
|
||||
return new GsonBuilder().registerTypeAdapter(KinoPlay.class, new KinoPlaySerializer()).create();
|
||||
}
|
||||
|
||||
@Bean
|
||||
public WebApp webapp(@Value("${webapp.host}") String host, @Value("${webapp.port}") int port) {
|
||||
return new WebApp(host, port);
|
||||
}
|
||||
|
||||
@Bean
|
||||
public ViewResolver viewResolver() {
|
||||
FreeMarkerViewResolver viewResolver = new FreeMarkerViewResolver();
|
||||
viewResolver.setContentType("text/html;charset=UTF-8");
|
||||
viewResolver.setCache(true);
|
||||
viewResolver.setSuffix(".ftl");
|
||||
return viewResolver;
|
||||
}
|
||||
|
||||
@Bean
|
||||
public FreeMarkerConfigurer freemarkerConfig() {
|
||||
FreeMarkerConfigurer freeMarkerConfigurer = new FreeMarkerConfigurer();
|
||||
freeMarkerConfigurer.setTemplateLoaderPath("classpath:/kinosearch/webapp/");
|
||||
return freeMarkerConfigurer;
|
||||
}
|
||||
}
|
||||
@@ -4,14 +4,34 @@
|
||||
*/
|
||||
package kinosearch.webapp;
|
||||
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.web.servlet.ViewResolver;
|
||||
import org.springframework.web.servlet.config.annotation.EnableWebMvc;
|
||||
import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
|
||||
import org.springframework.web.servlet.config.annotation.WebMvcConfigurerAdapter;
|
||||
import org.springframework.web.servlet.view.freemarker.FreeMarkerConfigurer;
|
||||
import org.springframework.web.servlet.view.freemarker.FreeMarkerViewResolver;
|
||||
|
||||
@Configuration
|
||||
@EnableWebMvc
|
||||
public class SpringMvcConfig extends WebMvcConfigurerAdapter {
|
||||
@Bean
|
||||
public ViewResolver viewResolver() {
|
||||
FreeMarkerViewResolver viewResolver = new FreeMarkerViewResolver();
|
||||
viewResolver.setContentType("text/html;charset=UTF-8");
|
||||
viewResolver.setCache(true);
|
||||
viewResolver.setSuffix(".ftl");
|
||||
return viewResolver;
|
||||
}
|
||||
|
||||
@Bean
|
||||
public FreeMarkerConfigurer freemarkerConfig() {
|
||||
FreeMarkerConfigurer freeMarkerConfigurer = new FreeMarkerConfigurer();
|
||||
freeMarkerConfigurer.setTemplateLoaderPath("classpath:/kinosearch/webapp/");
|
||||
return freeMarkerConfigurer;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addResourceHandlers(ResourceHandlerRegistry registry) {
|
||||
final String staticPath = "classpath:/kinosearch/webapp/static/";
|
||||
|
||||
@@ -2,7 +2,7 @@ package kinosearch.core.browser;
|
||||
|
||||
import com.google.gson.Gson;
|
||||
import com.google.gson.JsonObject;
|
||||
import kinosearch.webapp.SpringConfig;
|
||||
import kinosearch.core.SpringConfig;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
|
||||
@@ -4,7 +4,7 @@
|
||||
*/
|
||||
package kinosearch.core.warez;
|
||||
|
||||
import kinosearch.webapp.SpringConfig;
|
||||
import kinosearch.core.SpringConfig;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
|
||||
@@ -4,7 +4,7 @@
|
||||
*/
|
||||
package kinosearch.core.warez;
|
||||
|
||||
import kinosearch.webapp.SpringConfig;
|
||||
import kinosearch.core.SpringConfig;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
|
||||
Reference in New Issue
Block a user