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

时间:2016-01-24 14:53:56

标签: java eclipse spring gradle digital-ocean

我正在尝试使用eclipse,java,gradle,spring-boot构建一个安静的服务,并将其托管在数字海洋服务器上。我想在特定端口或某物上访问数字海洋网址时获得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] 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)

来自数字海洋:

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: [/*]

我的猜测是,出于某种原因,我的数字海洋服务器并不能与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并直接进入默认的数字海洋IP地址。

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

1 个答案:

答案 0 :(得分:2)

似乎应用程序被卡住了,因为它可能正在等待public void hover_Product_Category(){ action.moveToElement(product_Category).perform(); } (阻止设备,可能已经干了)。

您可以通过启动应用程序传递JVM-param /dev/random来使用/dev/urandom

请参阅Avoiding JVM Delays Caused by Random Number Generation

此外,要深入研究这些奇怪的问题,-Djava.security.egd=file:/dev/./urandomjstack等工具可能会有所帮助。