我正在尝试使用eclipse,java,gradle,spring-boot构建一个 Restful 服务,并将其托管在 digital ocean 服务器上。我想在特定端口或其他端口上访问 digital ocean URL时获得JSON响应,因此我可以执行123.456.78:90并在浏览器中看到JSON。
当我在eclipse中运行它并访问localhost时,这可以正常工作。访问localhost:port#会提供所需的输出,但是我注意到eclipse的控制台日志与在服务器上运行日志时有所不同。
从 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] o.s.b.f.s.DefaultListableBeanFactory : 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] s.b.c.e.t.TomcatEmbeddedServletContainer : 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] o.a.c.c.C.[Tomcat].[localhost].[/] : Initializing Spring embedded WebApplicationContext
2016-01-24 09:42:57.599 INFO 7372 --- [ost-startStop-1] o.s.web.context.ContextLoader : Root WebApplicationContext: initialization completed in 1301 ms
2016-01-24 09:42:57.880 INFO 7372 --- [ost-startStop-1] o.s.b.c.e.ServletRegistrationBean : Mapping servlet: 'dispatcherServlet' to [/]
2016-01-24 09:42:57.883 INFO 7372 --- [ost-startStop-1] o.s.b.c.embedded.FilterRegistrationBean : Mapping filter: 'characterEncodingFilter' to: [/*]
2016-01-24 09:42:57.884 INFO 7372 --- [ost-startStop-1] o.s.b.c.embedded.FilterRegistrationBean : Mapping filter: 'hiddenHttpMethodFilter' to: [/*]
2016-01-24 09:42:57.884 INFO 7372 --- [ost-startStop-1] o.s.b.c.embedded.FilterRegistrationBean : Mapping filter: 'httpPutFormContentFilter' to: [/*]
2016-01-24 09:42:57.885 INFO 7372 --- [ost-startStop-1] o.s.b.c.embedded.FilterRegistrationBean : Mapping filter: 'requestContextFilter' to: [/*]
2016-01-24 09:42:58.120 INFO 7372 --- [ main] s.w.s.m.m.a.RequestMappingHandlerAdapter : 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] s.w.s.m.m.a.RequestMappingHandlerMapping : 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] s.w.s.m.m.a.RequestMappingHandlerMapping : 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] s.w.s.m.m.a.RequestMappingHandlerMapping : Mapped "{[/error]}" onto public org.springframework.http.ResponseEntity<java.util.Map<java.lang.String, java.lang.Object>> org.springframework.boot.autoconfigure.web.BasicErrorController.error(javax.servlet.http.HttpServletRequest)
2016-01-24 09:42:58.186 INFO 7372 --- [ main] s.w.s.m.m.a.RequestMappingHandlerMapping : 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] o.s.w.s.handler.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] o.s.w.s.handler.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] o.s.w.s.handler.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] o.s.j.e.a.AnnotationMBeanExporter : Registering beans for JMX exposure on startup
2016-01-24 09:42:58.402 INFO 7372 --- [ main] s.b.c.e.t.TomcatEmbeddedServletContainer : 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)
来自 digital ocean :
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] o.s.b.f.s.DefaultListableBeanFactory : 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] s.b.c.e.t.TomcatEmbeddedServletContainer : 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] o.a.c.c.C.[Tomcat].[localhost].[/] : Initializing Spring embedded WebApplicationContext
2016-01-24 09:22:21.016 INFO 29453 --- [ost-startStop-1] o.s.web.context.ContextLoader : Root WebApplicationContext: initialization completed in 9086 ms
2016-01-24 09:22:22.582 INFO 29453 --- [ost-startStop-1] o.s.b.c.e.ServletRegistrationBean : Mapping servlet: 'dispatcherServlet' to [/]
2016-01-24 09:22:22.613 INFO 29453 --- [ost-startStop-1] o.s.b.c.embedded.FilterRegistrationBean : Mapping filter: 'characterEncodingFilter' to: [/*]
2016-01-24 09:22:22.636 INFO 29453 --- [ost-startStop-1] o.s.b.c.embedded.FilterRegistrationBean : Mapping filter: 'hiddenHttpMethodFilter' to: [/*]
2016-01-24 09:22:22.637 INFO 29453 --- [ost-startStop-1] o.s.b.c.embedded.FilterRegistrationBean : Mapping filter: 'httpPutFormContentFilter' to: [/*]
2016-01-24 09:22:22.637 INFO 29453 --- [ost-startStop-1] o.s.b.c.embedded.FilterRegistrationBean : Mapping filter: 'requestContextFilter' to: [/*]
我的猜测是由于某种原因,我的 digital ocean 服务器无法与Tomcat配合使用。我通过
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并直接使用默认的 digital ocean IP地址也没有什么区别。我以前在 digital ocean 上运行过应用程序,通常这就像通过
ufw
打开特定端口并在该端口上运行该应用程序,然后通过互联网访问它一样简单。但是,我想了解正在发生的某些事情。 最佳答案
似乎该应用程序被卡死,因为它可能正在等待/dev/random
(阻塞设备,可能已耗尽)。
您可以通过通过传递JVM-param /dev/urandom
来启动应用程序来使用-Djava.security.egd=file:/dev/./urandom
。
参见Avoiding JVM Delays Caused by Random Number Generation
此外,要深入研究此类奇怪的问题,诸如jstack
或strace
之类的工具可能会有所帮助。
关于java - 使用spring-boot运行Java应用程序,并在digitalocean上进行gradle,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/34977206/