/
Main.java
37 lines (30 loc) · 1.14 KB
/
Main.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
package com.nio.http.server;
import org.springframework.context.annotation.AnnotationConfigApplicationContext;
import org.springframework.context.support.AbstractApplicationContext;
import com.nio.config.SpringConfig;
/**
* Main entry point for the web server to start up the web server. This is a
* spring-managed application for dependency injection.
*
* @author Jay Paulynice (jay.paulynice@gmail.com)
*/
public class Main {
/** Application context to get the spring beans */
private static AbstractApplicationContext ctx;
public static void main(final String[] args) {
// annotation configuration
ctx = new AnnotationConfigApplicationContext(SpringConfig.class);
// register hook to close the spring context when the app is shutdown
ctx.registerShutdownHook();
final Server server = ctx.getBean(Server.class);
while (true) {
server.run();
try {
// let the server kick off before any requests are made
Thread.sleep(100);
} catch (final InterruptedException e) {
server.shutdown();
}
}
}
}