gpt4 book ai didi

java - 在 digitalocean 上运行带有 spring-boot 和 gradle 的 java 应用程序

转载 作者:塔克拉玛干 更新时间:2023-11-02 19:16:14 25 4
gpt4 key购买 nike

我正在尝试使用 eclipse、java、gradle、spring-boot 构建一个 Restful 服务,并将其托管在 digital ocean 服务器上。当我访问特定端口上的 digital ocean url 或其他内容时,我想获得 JSON 响应,因此我可以执行 123.456.78:90 并在浏览器中查看 JSON。

当我在 eclipse 中运行它并访问本地主机时,它工作正常。访问 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(阻塞设备,可能已经耗尽)。

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

参见 Avoiding JVM Delays Caused by Random Number Generation

此外,要深入了解这些奇怪的问题,jstackstrace 等工具可能会有所帮助。

关于java - 在 digitalocean 上运行带有 spring-boot 和 gradle 的 java 应用程序,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34977206/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com