Первые наброски WebApp
This commit is contained in:
20
pom.xml
20
pom.xml
@@ -23,6 +23,7 @@
|
|||||||
<log4j.version>2.5</log4j.version>
|
<log4j.version>2.5</log4j.version>
|
||||||
<spring.version>4.3.7.RELEASE</spring.version>
|
<spring.version>4.3.7.RELEASE</spring.version>
|
||||||
<spring.mongodb.version>1.10.1.RELEASE</spring.mongodb.version>
|
<spring.mongodb.version>1.10.1.RELEASE</spring.mongodb.version>
|
||||||
|
<jetty.version>9.4.0.v20161208</jetty.version>
|
||||||
</properties>
|
</properties>
|
||||||
|
|
||||||
<dependencies>
|
<dependencies>
|
||||||
@@ -83,6 +84,25 @@
|
|||||||
</exclusions>
|
</exclusions>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
|
||||||
|
<!-- JETTY -->
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.eclipse.jetty</groupId>
|
||||||
|
<artifactId>jetty-server</artifactId>
|
||||||
|
<version>${jetty.version}</version>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.eclipse.jetty</groupId>
|
||||||
|
<artifactId>jetty-webapp</artifactId>
|
||||||
|
<version>${jetty.version}</version>
|
||||||
|
</dependency>
|
||||||
|
|
||||||
|
<!-- SPRING MVC -->
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.springframework</groupId>
|
||||||
|
<artifactId>spring-webmvc</artifactId>
|
||||||
|
<version>${spring.version}</version>
|
||||||
|
</dependency>
|
||||||
|
|
||||||
<!-- COMPONENTS -->
|
<!-- COMPONENTS -->
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>commons-io</groupId>
|
<groupId>commons-io</groupId>
|
||||||
|
|||||||
16
src/main/java/kinosearch/kinosearch3/webpp/Main.java
Normal file
16
src/main/java/kinosearch/kinosearch3/webpp/Main.java
Normal file
@@ -0,0 +1,16 @@
|
|||||||
|
/*
|
||||||
|
* DmitriyMX <dimon550@gmail.com>
|
||||||
|
* 2017-04-09
|
||||||
|
*/
|
||||||
|
package kinosearch.kinosearch3.webpp;
|
||||||
|
|
||||||
|
import org.springframework.context.ApplicationContext;
|
||||||
|
import org.springframework.context.annotation.AnnotationConfigApplicationContext;
|
||||||
|
|
||||||
|
public class Main {
|
||||||
|
public static void main(String[] args) {
|
||||||
|
ApplicationContext ctx = new AnnotationConfigApplicationContext(SpringConfig.class);
|
||||||
|
WebApp webApp = ctx.getBean("webapp", WebApp.class);
|
||||||
|
webApp.start();
|
||||||
|
}
|
||||||
|
}
|
||||||
19
src/main/java/kinosearch/kinosearch3/webpp/SpringConfig.java
Normal file
19
src/main/java/kinosearch/kinosearch3/webpp/SpringConfig.java
Normal file
@@ -0,0 +1,19 @@
|
|||||||
|
/*
|
||||||
|
* DmitriyMX <dimon550@gmail.com>
|
||||||
|
* 2017-04-09
|
||||||
|
*/
|
||||||
|
package kinosearch.kinosearch3.webpp;
|
||||||
|
|
||||||
|
import org.springframework.beans.factory.annotation.Value;
|
||||||
|
import org.springframework.context.annotation.Bean;
|
||||||
|
import org.springframework.context.annotation.Configuration;
|
||||||
|
import org.springframework.context.annotation.PropertySource;
|
||||||
|
|
||||||
|
@Configuration
|
||||||
|
@PropertySource("classpath:/application.properties")
|
||||||
|
public class SpringConfig {
|
||||||
|
@Bean
|
||||||
|
public WebApp webapp(@Value("${webapp.host}") String host, @Value("${webapp.port}") int port) {
|
||||||
|
return new WebApp(host, port);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,14 @@
|
|||||||
|
/*
|
||||||
|
* DmitriyMX <dimon550@gmail.com>
|
||||||
|
* 2017-04-09
|
||||||
|
*/
|
||||||
|
package kinosearch.kinosearch3.webpp;
|
||||||
|
|
||||||
|
import org.springframework.context.annotation.Configuration;
|
||||||
|
import org.springframework.web.servlet.config.annotation.EnableWebMvc;
|
||||||
|
import org.springframework.web.servlet.config.annotation.WebMvcConfigurerAdapter;
|
||||||
|
|
||||||
|
@Configuration
|
||||||
|
@EnableWebMvc
|
||||||
|
public class SpringMvcConfig extends WebMvcConfigurerAdapter {
|
||||||
|
}
|
||||||
60
src/main/java/kinosearch/kinosearch3/webpp/WebApp.java
Normal file
60
src/main/java/kinosearch/kinosearch3/webpp/WebApp.java
Normal file
@@ -0,0 +1,60 @@
|
|||||||
|
/*
|
||||||
|
* DmitriyMX <dimon550@gmail.com>
|
||||||
|
* 2017-04-09
|
||||||
|
*/
|
||||||
|
package kinosearch.kinosearch3.webpp;
|
||||||
|
|
||||||
|
import lombok.Getter;
|
||||||
|
import org.eclipse.jetty.server.Server;
|
||||||
|
import org.eclipse.jetty.servlet.ServletContextHandler;
|
||||||
|
import org.eclipse.jetty.servlet.ServletHolder;
|
||||||
|
import org.eclipse.jetty.util.log.Log;
|
||||||
|
import org.eclipse.jetty.util.log.Slf4jLog;
|
||||||
|
import org.slf4j.Logger;
|
||||||
|
import org.slf4j.LoggerFactory;
|
||||||
|
import org.springframework.web.context.ContextLoaderListener;
|
||||||
|
import org.springframework.web.context.WebApplicationContext;
|
||||||
|
import org.springframework.web.context.support.AnnotationConfigWebApplicationContext;
|
||||||
|
import org.springframework.web.servlet.DispatcherServlet;
|
||||||
|
|
||||||
|
import java.net.InetSocketAddress;
|
||||||
|
|
||||||
|
public class WebApp {
|
||||||
|
private final Logger logger = LoggerFactory.getLogger(WebApp.class);
|
||||||
|
@Getter
|
||||||
|
private final String host;
|
||||||
|
@Getter
|
||||||
|
private final int port;
|
||||||
|
|
||||||
|
public WebApp(String host, int port) {
|
||||||
|
this.host = host;
|
||||||
|
this.port = port;
|
||||||
|
}
|
||||||
|
|
||||||
|
void start() {
|
||||||
|
Log.setLog(new Slf4jLog("Jetty.Logger"));
|
||||||
|
Server server = new Server(new InetSocketAddress(host, port));
|
||||||
|
server.setHandler(getServletContextHandler(getContext()));
|
||||||
|
try {
|
||||||
|
server.start();
|
||||||
|
server.join();
|
||||||
|
} catch (Exception e) {
|
||||||
|
logger.error("Start server", e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private ServletContextHandler getServletContextHandler(WebApplicationContext context) {
|
||||||
|
ServletContextHandler contextHandler = new ServletContextHandler();
|
||||||
|
contextHandler.setErrorHandler(null);
|
||||||
|
contextHandler.setContextPath("/");
|
||||||
|
contextHandler.addServlet(new ServletHolder(new DispatcherServlet(context)), "/*");
|
||||||
|
contextHandler.addEventListener(new ContextLoaderListener(context));
|
||||||
|
return contextHandler;
|
||||||
|
}
|
||||||
|
|
||||||
|
private WebApplicationContext getContext() {
|
||||||
|
AnnotationConfigWebApplicationContext context = new AnnotationConfigWebApplicationContext();
|
||||||
|
context.setConfigLocation("kinosearch.kinosearch3.webpp");
|
||||||
|
return context;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,19 @@
|
|||||||
|
/*
|
||||||
|
* DmitriyMX <dimon550@gmail.com>
|
||||||
|
* 2017-04-09
|
||||||
|
*/
|
||||||
|
package kinosearch.kinosearch3.webpp;
|
||||||
|
|
||||||
|
import org.springframework.stereotype.Controller;
|
||||||
|
import org.springframework.web.bind.annotation.RequestMapping;
|
||||||
|
import org.springframework.web.bind.annotation.RequestMethod;
|
||||||
|
import org.springframework.web.bind.annotation.ResponseBody;
|
||||||
|
|
||||||
|
@Controller
|
||||||
|
public class WebAppController {
|
||||||
|
@RequestMapping(value = "/", method = RequestMethod.GET)
|
||||||
|
@ResponseBody
|
||||||
|
public String hello() {
|
||||||
|
return "hello...?";
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -2,3 +2,6 @@ mongo.host=127.0.0.1
|
|||||||
mongo.port=27017
|
mongo.port=27017
|
||||||
mongo.db=kinosearch
|
mongo.db=kinosearch
|
||||||
saveRootDir=R:\\
|
saveRootDir=R:\\
|
||||||
|
|
||||||
|
webapp.host=127.0.0.1
|
||||||
|
webapp.port=8080
|
||||||
Reference in New Issue
Block a user