4
4
import tech .smartboot .servlet .Container ;
5
5
import tech .smartboot .servlet .ServletContextRuntime ;
6
6
import tech .smartboot .servlet .conf .ServletInfo ;
7
- import tech .smartboot .servlet .conf .ServletMappingInfo ;
8
7
9
8
/**
10
9
13
12
public class Bootstrap {
14
13
15
14
public static void main (String [] args ) throws Throwable {
16
- System .setProperty ("smart-servlet-spring-boot-starter" ,"true" );
15
+ System .setProperty ("smart-servlet-spring-boot-starter" , "true" );
17
16
Container containerRuntime = new Container ();
18
17
// plaintext
19
18
ServletContextRuntime applicationRuntime = new ServletContextRuntime (null , Thread .currentThread ().getContextClassLoader (), "/" );
@@ -23,23 +22,24 @@ public static void main(String[] args) throws Throwable {
23
22
ServletInfo plainTextServletInfo = new ServletInfo ();
24
23
plainTextServletInfo .setServletName ("plaintext" );
25
24
plainTextServletInfo .setServletClass (HelloWorldServlet .class .getName ());
26
- applicationRuntime . getDeploymentInfo (). addServletMapping (new ServletMappingInfo ( plainTextServletInfo . getServletName (), "/plaintext" ) );
25
+ plainTextServletInfo . addServletMapping ("/plaintext" , applicationRuntime );
27
26
applicationRuntime .getDeploymentInfo ().addServlet (plainTextServletInfo );
28
27
29
28
// json
30
29
ServletInfo jsonServletInfo = new ServletInfo ();
31
30
jsonServletInfo .setServletName ("json" );
32
31
jsonServletInfo .setServletClass (JsonServlet .class .getName ());
32
+ jsonServletInfo .addServletMapping ("/json" , applicationRuntime );
33
33
applicationRuntime .getDeploymentInfo ().addServlet (jsonServletInfo );
34
- applicationRuntime .getDeploymentInfo ().addServletMapping (new ServletMappingInfo (jsonServletInfo .getServletName (), "/json" ));
35
34
containerRuntime .addRuntime (applicationRuntime );
36
35
int cpuNum = Runtime .getRuntime ().availableProcessors ();
37
36
// 定义服务器接受的消息类型以及各类消息对应的处理器
38
37
containerRuntime .getConfiguration ()
39
38
.setThreadNum (cpuNum )
39
+ .setHeaderLimiter (0 )
40
40
.setReadBufferSize (1024 * 4 );
41
41
containerRuntime .initialize ();
42
42
containerRuntime .start ();
43
-
43
+
44
44
}
45
45
}
0 commit comments