使用spring-boot运行java应用程序,并在digitalocean上运行gradle

我正在尝试使用eclipse,java,gradle,spring-boot构建一个宁静的服务,并将其托管在数字海洋服务器上。 我想在特定端口或某物上访问数字海洋url时获得JSON响应,因此我可以执行123.456.78:90并在浏览器中查看JSON。

当我在eclipse中运行它并访问localhost时,这很好用。 访问localhost:port#给出了所需的输出,但是我注意到控制台日志与eclipse之间的区别以及我在服务器上运行时的差异。

从日食:

2016-01-24 09:42:56.245 INFO 7372 --- [ main] Keen.KeenAPICallTester : Starting KeenAPICallTester on ****-THINK with PID 7372 (C:\Users\****\workspace\****-ML\bin started by **** in C:\Users\****\workspace\****-ML) 2016-01-24 09:42:56.247 INFO 7372 --- [ main] Keen.KeenAPICallTester : No active profile set, falling back to default profiles: default 2016-01-24 09:42:56.299 INFO 7372 --- [ main] ationConfigEmbeddedWebApplicationContext : Refreshing org.springframework.boot.context.embedded.AnnotationConfigEmbeddedWebApplicationContext@116af24: startup date [Sun Jan 24 09:42:56 EST 2016]; root of context hierarchy 2016-01-24 09:42:56.893 INFO 7372 --- [ main] osbfsDefaultListableBeanFactory : Overriding bean definition for bean 'beanNameViewResolver' with a different definition: replacing [Root bean: class [null]; scope=; abstract=false; lazyInit=false; autowireMode=3; dependencyCheck=0; autowireCandidate=true; primary=false; factoryBeanName=org.springframework.boot.autoconfigure.web.ErrorMvcAutoConfiguration$WhitelabelErrorViewConfiguration; factoryMethodName=beanNameViewResolver; initMethodName=null; destroyMethodName=(inferred); defined in class path resource [org/springframework/boot/autoconfigure/web/ErrorMvcAutoConfiguration$WhitelabelErrorViewConfiguration.class]] with [Root bean: class [null]; scope=; abstract=false; lazyInit=false; autowireMode=3; dependencyCheck=0; autowireCandidate=true; primary=false; factoryBeanName=org.springframework.boot.autoconfigure.web.WebMvcAutoConfiguration$WebMvcAutoConfigurationAdapter; factoryMethodName=beanNameViewResolver; initMethodName=null; destroyMethodName=(inferred); defined in class path resource [org/springframework/boot/autoconfigure/web/WebMvcAutoConfiguration$WebMvcAutoConfigurationAdapter.class]] 2016-01-24 09:42:57.492 INFO 7372 --- [ main] sbcetTomcatEmbeddedServletContainer : Tomcat initialized with port(s): 9011 (http) 2016-01-24 09:42:57.502 INFO 7372 --- [ main] o.apache.catalina.core.StandardService : Starting service Tomcat 2016-01-24 09:42:57.503 INFO 7372 --- [ main] org.apache.catalina.core.StandardEngine : Starting Servlet Engine: Apache Tomcat/8.0.30 2016-01-24 09:42:57.599 INFO 7372 --- [ost-startStop-1] oaccC[Tomcat].[localhost].[/] : Initializing Spring embedded WebApplicationContext 2016-01-24 09:42:57.599 INFO 7372 --- [ost-startStop-1] osweb.context.ContextLoader : Root WebApplicationContext: initialization completed in 1301 ms 2016-01-24 09:42:57.880 INFO 7372 --- [ost-startStop-1] osbceServletRegistrationBean : Mapping servlet: 'dispatcherServlet' to [/] 2016-01-24 09:42:57.883 INFO 7372 --- [ost-startStop-1] osbcembedded.FilterRegistrationBean : Mapping filter: 'characterEncodingFilter' to: [/*] 2016-01-24 09:42:57.884 INFO 7372 --- [ost-startStop-1] osbcembedded.FilterRegistrationBean : Mapping filter: 'hiddenHttpMethodFilter' to: [/*] 2016-01-24 09:42:57.884 INFO 7372 --- [ost-startStop-1] osbcembedded.FilterRegistrationBean : Mapping filter: 'httpPutFormContentFilter' to: [/*] 2016-01-24 09:42:57.885 INFO 7372 --- [ost-startStop-1] osbcembedded.FilterRegistrationBean : Mapping filter: 'requestContextFilter' to: [/*] 2016-01-24 09:42:58.120 INFO 7372 --- [ main] swsmmaRequestMappingHandlerAdapter : Looking for @ControllerAdvice: org.springframework.boot.context.embedded.AnnotationConfigEmbeddedWebApplicationContext@116af24: startup date [Sun Jan 24 09:42:56 EST 2016]; root of context hierarchy 2016-01-24 09:42:58.183 INFO 7372 --- [ main] swsmmaRequestMappingHandlerMapping : Mapped "{[/extractionTest],methods=[GET],produces=[application/json]}" onto public java.lang.Object Keen.MLJSONResponseController.testExtractionRequest() 2016-01-24 09:42:58.184 INFO 7372 --- [ main] swsmmaRequestMappingHandlerMapping : Mapped "{[/inspectAllProjectsTest],methods=[GET],produces=[application/json]}" onto public java.lang.Object Keen.MLJSONResponseController.testInspectionRequest() 2016-01-24 09:42:58.186 INFO 7372 --- [ main] swsmmaRequestMappingHandlerMapping : Mapped "{[/error]}" onto public org.springframework.http.ResponseEntity<java.util.Map> org.springframework.boot.autoconfigure.web.BasicErrorController.error(javax.servlet.http.HttpServletRequest) 2016-01-24 09:42:58.186 INFO 7372 --- [ main] swsmmaRequestMappingHandlerMapping : Mapped "{[/error],produces=[text/html]}" onto public org.springframework.web.servlet.ModelAndView org.springframework.boot.autoconfigure.web.BasicErrorController.errorHtml(javax.servlet.http.HttpServletRequest,javax.servlet.http.HttpServletResponse) 2016-01-24 09:42:58.208 INFO 7372 --- [ main] oswshandler.SimpleUrlHandlerMapping : Mapped URL path [/webjars/**] onto handler of type [class org.springframework.web.servlet.resource.ResourceHttpRequestHandler] 2016-01-24 09:42:58.208 INFO 7372 --- [ main] oswshandler.SimpleUrlHandlerMapping : Mapped URL path [/**] onto handler of type [class org.springframework.web.servlet.resource.ResourceHttpRequestHandler] 2016-01-24 09:42:58.246 INFO 7372 --- [ main] oswshandler.SimpleUrlHandlerMapping : Mapped URL path [/**/favicon.ico] onto handler of type [class org.springframework.web.servlet.resource.ResourceHttpRequestHandler] 2016-01-24 09:42:58.349 INFO 7372 --- [ main] osjeaAnnotationMBeanExporter : Registering beans for JMX exposure on startup 2016-01-24 09:42:58.402 INFO 7372 --- [ main] sbcetTomcatEmbeddedServletContainer : Tomcat started on port(s): 9011 (http) 2016-01-24 09:42:58.406 INFO 7372 --- [ main] Keen.KeenAPICallTester : Started KeenAPICallTester in 2.445 seconds (JVM running for 2.739) 

来自数字海洋:

 2016-01-24 09:22:11.190 INFO 29453 --- [ main] Keen.KeenAPICallTester : Starting KeenAPICallTester on **** with PID 29453 (/root/java-ml/learning/build/classes/main started by root in /root/java-ml/learning) 2016-01-24 09:22:11.224 INFO 29453 --- [ main] Keen.KeenAPICallTester : No active profile set, falling back to default profiles: default 2016-01-24 09:22:11.949 INFO 29453 --- [ main] ationConfigEmbeddedWebApplicationContext : Refreshing org.springframework.boot.context.embedded.AnnotationConfigEmbeddedWebApplicationContext@8b87145: startup date [Sun Jan 24 09:22:11 EST 2016]; root of context hierarchy 2016-01-24 09:22:16.874 INFO 29453 --- [ main] osbfsDefaultListableBeanFactory : Overriding bean definition for bean 'beanNameViewResolver' with a different definition: replacing [Root bean: class [null]; scope=; abstract=false; lazyInit=false; autowireMode=3; dependencyCheck=0; autowireCandidate=true; primary=false; factoryBeanName=org.springframework.boot.autoconfigure.web.ErrorMvcAutoConfiguration$WhitelabelErrorViewConfiguration; factoryMethodName=beanNameViewResolver; initMethodName=null; destroyMethodName=(inferred); defined in class path resource [org/springframework/boot/autoconfigure/web/ErrorMvcAutoConfiguration$WhitelabelErrorViewConfiguration.class]] with [Root bean: class [null]; scope=; abstract=false; lazyInit=false; autowireMode=3; dependencyCheck=0; autowireCandidate=true; primary=false; factoryBeanName=org.springframework.boot.autoconfigure.web.WebMvcAutoConfiguration$WebMvcAutoConfigurationAdapter; factoryMethodName=beanNameViewResolver; initMethodName=null; destroyMethodName=(inferred); defined in class path resource [org/springframework/boot/autoconfigure/web/WebMvcAutoConfiguration$WebMvcAutoConfigurationAdapter.class]] 2016-01-24 09:22:20.350 INFO 29453 --- [ main] sbcetTomcatEmbeddedServletContainer : Tomcat initialized with port(s): 80 (http) 2016-01-24 09:22:20.448 INFO 29453 --- [ main] o.apache.catalina.core.StandardService : Starting service Tomcat 2016-01-24 09:22:20.457 INFO 29453 --- [ main] org.apache.catalina.core.StandardEngine : Starting Servlet Engine: Apache Tomcat/8.0.30 2016-01-24 09:22:21.015 INFO 29453 --- [ost-startStop-1] oaccC[Tomcat].[localhost].[/] : Initializing Spring embedded WebApplicationContext 2016-01-24 09:22:21.016 INFO 29453 --- [ost-startStop-1] osweb.context.ContextLoader : Root WebApplicationContext: initialization completed in 9086 ms 2016-01-24 09:22:22.582 INFO 29453 --- [ost-startStop-1] osbceServletRegistrationBean : Mapping servlet: 'dispatcherServlet' to [/] 2016-01-24 09:22:22.613 INFO 29453 --- [ost-startStop-1] osbcembedded.FilterRegistrationBean : Mapping filter: 'characterEncodingFilter' to: [/*] 2016-01-24 09:22:22.636 INFO 29453 --- [ost-startStop-1] osbcembedded.FilterRegistrationBean : Mapping filter: 'hiddenHttpMethodFilter' to: [/*] 2016-01-24 09:22:22.637 INFO 29453 --- [ost-startStop-1] osbcembedded.FilterRegistrationBean : Mapping filter: 'httpPutFormContentFilter' to: [/*] 2016-01-24 09:22:22.637 INFO 29453 --- [ost-startStop-1] osbcembedded.FilterRegistrationBean : Mapping filter: 'requestContextFilter' to: [/*] 

我的猜测是,由于某些原因,我的数字海洋服务器不能与Tomcat或其他东西玩得很好。 我通过ufw命令打开了ufw ,检查了iptables,安装了apache2(我甚至不知道我是否必须诚实)并确保配置设置为接受端口8080和8000中的出站和入站请求。

我注意到我的请求方法没有被映射,这让我觉得存在一些依赖性问题。 这是我的build.gradle供参考。

 buildscript { repositories { mavenCentral() } dependencies { classpath("org.springframework.boot:spring-boot-gradle-plugin:1.3.1.RELEASE") } } apply plugin: 'java' apply plugin: 'application' apply plugin: 'eclipse' apply plugin: 'idea' apply plugin: 'spring-boot' mainClassName = "Keen.KeenAPICallTester" applicationDefaultJvmArgs = ["--server.port=8000"] jar { baseName = '****-ML' version = '0.1.0' } repositories { mavenCentral() } sourceCompatibility = 1.8 targetCompatibility = 1.8 dependencies { compile("org.springframework.boot:spring-boot-starter-web") testCompile("junit:junit") compile fileTree(dir: 'libs', include: '*.jar') } task wrapper(type: Wrapper) { gradleVersion = '2.3' } task(runSimple, dependsOn: 'classes', type: JavaExec) { main = 'Keen.KeenAPICallTester' classpath = sourceSets.main.runtimeClasspath args '--server.port=8000' } 

我处理这个问题的方式有问题吗? 我也有一个runSimple命令,以便我可以使用JVM端口运行,但它没有任何区别,即使我将它设置为80并直接进入默认的数字海洋IP地址。

我之前在数字海洋上运行应用程序,通常它就像通过ufw特定端口并在端口上运行应用程序,然后通过互联网访问它一样简单。 但是我想要了解的内容正在进行中。

似乎应用程序被卡住了,因为它可能正在等待/dev/random (阻塞设备,可能已经干了)。

你可以使用/dev/urandom来启动你的应用程序传递JVM-param -Djava.security.egd=file:/dev/./urandom

请参阅避免由随机数生成引起的JVM延迟

此外,为了深入研究这些奇怪的问题,诸如jstackstrace工具可能会有所帮助。