jvm选项-Dserver.port=-1
是什么意思?我知道将它设置为0表示随机端口。有一篇很好的文章here。
答案 0 :(得分:1)
这意味着“创建一个WebApplicationContext,但不要启动服务器”。
答案 1 :(得分:0)
让我们看看从运行不同选项的同一个测试弹簧应用程序中截取的两个截图。
C:\>java -jar -Dserver.contextPath=/testapp -Dserver.port=0 spring-security-test-0.0.1-SNAPSHOT.jar . ____ _ __ _ _ /\\ / ___'_ __ _ _(_)_ __ __ _ \ \ \ \ ( ( )\___ | '_ | '_| | '_ \/ _` | \ \ \ \ \\/ ___)| |_)| | | | | || (_| | ) ) ) ) ' |____| .__|_| |_|_| |_\__, | / / / / =========|_|==============|___/=/_/_/_/ :: Spring Boot :: (v1.0.2.RELEASE) 2014-05-29 10:22:36.434 INFO 10172 --- [ main] s.t.spring.security.config.Application : Starting Application on KOLTM28902K0NX with PID 10172 (C:\spring-security-test- 0.0.1-SNAPSHOT.jar started by 607130889 in C:\) 2014-05-29 10:22:36.481 INFO 10172 --- [ main] ationConfigEmbeddedWebApplicationContext : Refreshing org.springframework.boot.context.embedded.AnnotationConfigEmbeddedWe bApplicationContext@1d256fa: startup date [Thu May 29 10:22:36 IST 2014]; root of context hierarchy 2014-05-29 10:22:37.619 INFO 10172 --- [ main] .t.TomcatEmbeddedServletContainerFactory : Server initialized with port: 0 2014-05-29 10:22:37.744 INFO 10172 --- [ main] o.apache.catalina.core.StandardService : Starting service Tomcat 2014-05-29 10:22:37.744 INFO 10172 --- [ main] org.apache.catalina.core.StandardEngine : Starting Servlet Engine: Apache Tomcat/7.0.52 2014-05-29 10:22:37.853 INFO 10172 --- [ost-startStop-1] o.a.c.c.C.[.[localhost].[/testapp] : Initializing Spring embedded WebApplicationContext 2014-05-29 10:22:37.853 INFO 10172 --- [ost-startStop-1] o.s.web.context.ContextLoader : Root WebApplicationContext: initialization completed in 1372 ms 2014-05-29 10:22:38.805 INFO 10172 --- [ost-startStop-1] o.s.s.web.DefaultSecurityFilterChain : Creating filter chain: org.springframework.security.web.util.matcher.AnyRequest Matcher@1, [org.springframework.security.web.context.request.async.WebAsyncManagerIntegrationFilter@a30fd, org.springframework.security.web.context.SecurityContextPersistenceFilter @cad437, org.springframework.security.web.header.HeaderWriterFilter@1f18cbe, org.springframework.security.web.csrf.CsrfFilter@725967, org.springframework.security.web.authenticatio n.logout.LogoutFilter@1ed688f, org.springframework.security.web.authentication.UsernamePasswordAuthenticationFilter@10ff62a, org.springframework.security.web.savedrequest.RequestCa cheAwareFilter@f18d37, org.springframework.security.web.servletapi.SecurityContextHolderAwareRequestFilter@1c0b8a0, org.springframework.security.web.authentication.AnonymousAuthent icationFilter@11650d6, org.springframework.security.web.session.SessionManagementFilter@178c490, org.springframework.security.web.access.ExceptionTranslationFilter@1de7497, org.spr ingframework.security.web.access.intercept.FilterSecurityInterceptor@4d28c7] 2014-05-29 10:22:38.867 INFO 10172 --- [ost-startStop-1] o.s.b.c.e.ServletRegistrationBean : Mapping servlet: 'dispatcherServlet' to [/] 2014-05-29 10:22:38.867 INFO 10172 --- [ost-startStop-1] o.s.b.c.embedded.FilterRegistrationBean : Mapping filter: 'springSecurityFilterChain' to: [/*] 2014-05-29 10:22:38.867 INFO 10172 --- [ost-startStop-1] o.s.b.c.embedded.FilterRegistrationBean : Mapping filter: 'hiddenHttpMethodFilter' to: [/*] 2014-05-29 10:22:39.148 INFO 10172 --- [ main] o.s.w.s.handler.SimpleUrlHandlerMapping : Mapped URL path [/**/favicon.ico] onto handler of type [class org.springframewo rk.web.servlet.resource.ResourceHttpRequestHandler] 2014-05-29 10:22:39.211 INFO 10172 --- [ main] o.s.w.s.handler.SimpleUrlHandlerMapping : Mapped URL path [/hello] onto handler of type [class org.springframework.web.se rvlet.mvc.ParameterizableViewController] 2014-05-29 10:22:39.211 INFO 10172 --- [ main] o.s.w.s.handler.SimpleUrlHandlerMapping : Mapped URL path [/home] onto handler of type [class org.springframework.web.ser vlet.mvc.ParameterizableViewController] 2014-05-29 10:22:39.211 INFO 10172 --- [ main] o.s.w.s.handler.SimpleUrlHandlerMapping : Mapped URL path [/login] onto handler of type [class org.springframework.web.se rvlet.mvc.ParameterizableViewController] 2014-05-29 10:22:39.211 INFO 10172 --- [ main] o.s.w.s.handler.SimpleUrlHandlerMapping : Root mapping to handler of type [class org.springframework.web.servlet.mvc.Para meterizableViewController] 2014-05-29 10:22:39.273 INFO 10172 --- [ main] o.s.w.s.handler.SimpleUrlHandlerMapping : Mapped URL path [/**] onto handler of type [class org.springframework.web.servl et.resource.ResourceHttpRequestHandler] 2014-05-29 10:22:39.273 INFO 10172 --- [ main] o.s.w.s.handler.SimpleUrlHandlerMapping : Mapped URL path [/webjars/**] onto handler of type [class org.springframework.w eb.servlet.resource.ResourceHttpRequestHandler] 2014-05-29 10:22:39.585 INFO 10172 --- [ main] o.s.j.e.a.AnnotationMBeanExporter : Registering beans for JMX exposure on startup 2014-05-29 10:22:39.663 INFO 10172 --- [ main] s.b.c.e.t.TomcatEmbeddedServletContainer : Tomcat started on port(s): 56822/http 2014-05-29 10:22:39.663 INFO 10172 --- [ main] s.t.spring.security.config.Application : Started Application in 3.666 seconds (JVM running for 4.056)
当应用程序与-Dserver.port=0
一起运行时,我们可以看到服务器以随机端口启动。
. ____ _ __ _ _ /\\ / ___'_ __ _ _(_)_ __ __ _ \ \ \ \ ( ( )\___ | '_ | '_| | '_ \/ _` | \ \ \ \ \\/ ___)| |_)| | | | | || (_| | ) ) ) ) ' |____| .__|_| |_|_| |_\__, | / / / / =========|_|==============|___/=/_/_/_/ :: Spring Boot :: (v1.0.2.RELEASE) 2014-05-29 09:59:31.815 INFO 2756 --- [ main] s.t.spring.security.config.Application : Starting Application on KOLTM28902K0NX with PID 2756 (C:\Users\607130889\Share\s pring-security-test-0.0.1-SNAPSHOT.jar started by 607130889 in C:\Users\607130889\Share) 2014-05-29 09:59:31.908 INFO 2756 --- [ main] ationConfigEmbeddedWebApplicationContext : Refreshing org.springframework.boot.context.embedded.AnnotationConfigEmbeddedWeb ApplicationContext@1c5f743: startup date [Thu May 29 09:59:31 IST 2014]; root of context hierarchy 2014-05-29 09:59:34.295 INFO 2756 --- [ main] .t.TomcatEmbeddedServletContainerFactory : Server initialized with port: -1 2014-05-29 09:59:34.748 INFO 2756 --- [ main] o.apache.catalina.core.StandardService : Starting service Tomcat 2014-05-29 09:59:34.748 INFO 2756 --- [ main] org.apache.catalina.core.StandardEngine : Starting Servlet Engine: Apache Tomcat/7.0.52 2014-05-29 09:59:35.013 INFO 2756 --- [ost-startStop-1] o.a.c.c.C.[.[localhost].[/secure] : Initializing Spring embedded WebApplicationContext 2014-05-29 09:59:35.013 INFO 2756 --- [ost-startStop-1] o.s.web.context.ContextLoader : Root WebApplicationContext: initialization completed in 3105 ms 2014-05-29 09:59:36.526 INFO 2756 --- [ost-startStop-1] o.s.s.web.DefaultSecurityFilterChain : Creating filter chain: org.springframework.security.web.util.matcher.AnyRequestM atcher@1, [org.springframework.security.web.context.request.async.WebAsyncManagerIntegrationFilter@167c6fd, org.springframework.security.web.context.SecurityContextPersistenceFilte r@139d115, org.springframework.security.web.header.HeaderWriterFilter@19d9c0d, org.springframework.security.web.csrf.CsrfFilter@1384ed5, org.springframework.security.web.authentica tion.logout.LogoutFilter@14189d0, org.springframework.security.web.authentication.UsernamePasswordAuthenticationFilter@2cd728, org.springframework.security.web.savedrequest.Request CacheAwareFilter@83de21, org.springframework.security.web.servletapi.SecurityContextHolderAwareRequestFilter@1b2380e, org.springframework.security.web.authentication.AnonymousAuthe nticationFilter@39452f, org.springframework.security.web.session.SessionManagementFilter@154c054, org.springframework.security.web.access.ExceptionTranslationFilter@5db9eb, org.springframework.security.web.access.intercept.FilterSecurityInterceptor@1353154] 2014-05-29 09:59:36.589 INFO 2756 --- [ost-startStop-1] o.s.b.c.e.ServletRegistrationBean : Mapping servlet: 'dispatcherServlet' to [/] 2014-05-29 09:59:36.604 INFO 2756 --- [ost-startStop-1] o.s.b.c.embedded.FilterRegistrationBean : Mapping filter: 'springSecurityFilterChain' to: [/*] 2014-05-29 09:59:36.604 INFO 2756 --- [ost-startStop-1] o.s.b.c.embedded.FilterRegistrationBean : Mapping filter: 'hiddenHttpMethodFilter' to: [/*] 2014-05-29 09:59:37.213 INFO 2756 --- [ main] o.s.w.s.handler.SimpleUrlHandlerMapping : Mapped URL path [/**/favicon.ico] onto handler of type [class org.springframewor k.web.servlet.resource.ResourceHttpRequestHandler] 2014-05-29 09:59:37.415 INFO 2756 --- [ main] o.s.w.s.handler.SimpleUrlHandlerMapping : Mapped URL path [/hello] onto handler of type [class org.springframework.web.ser vlet.mvc.ParameterizableViewController] 2014-05-29 09:59:37.415 INFO 2756 --- [ main] o.s.w.s.handler.SimpleUrlHandlerMapping : Mapped URL path [/home] onto handler of type [class org.springframework.web.serv let.mvc.ParameterizableViewController] 2014-05-29 09:59:37.415 INFO 2756 --- [ main] o.s.w.s.handler.SimpleUrlHandlerMapping : Mapped URL path [/login] onto handler of type [class org.springframework.web.ser vlet.mvc.ParameterizableViewController] 2014-05-29 09:59:37.415 INFO 2756 --- [ main] o.s.w.s.handler.SimpleUrlHandlerMapping : Root mapping to handler of type [class org.springframework.web.servlet.mvc.Param eterizableViewController] 2014-05-29 09:59:37.431 INFO 2756 --- [ main] o.s.w.s.handler.SimpleUrlHandlerMapping : Mapped URL path [/**] onto handler of type [class org.springframework.web.servle t.resource.ResourceHttpRequestHandler] 2014-05-29 09:59:37.431 INFO 2756 --- [ main] o.s.w.s.handler.SimpleUrlHandlerMapping : Mapped URL path [/webjars/**] onto handler of type [class org.springframework.web.servlet.resource.ResourceHttpRequestHandler] 2014-05-29 09:59:37.805 INFO 2756 --- [ main] o.s.j.e.a.AnnotationMBeanExporter : Registering beans for JMX exposure on startup 2014-05-29 09:59:37.868 INFO 2756 --- [ main] s.t.spring.security.config.Application : Started Application in 7.551 seconds (JVM running for 9.08)
当使用server.port=-1
操作运行应用程序时,缺少服务器启动通知。