在这篇文章中,我们将为您详细介绍如何在SpringBoot应用程序启动时启动H2TCP服务器?的内容,并且讨论关于springboot启动端口的相关问题。此外,我们还会涉及一些关于java–sprin
在这篇文章中,我们将为您详细介绍如何在Spring Boot应用程序启动时启动H2 TCP服务器?的内容,并且讨论关于spring boot启动端口的相关问题。此外,我们还会涉及一些关于java – spring-boot应用程序无法启动、java – Spring-boot应用程序无法在docker内启动时启动、java – 在SpringBoot应用程序启动时捕获Hibernate异常?、java – 测试启动Spring-boot应用程序的知识,以帮助您更全面地了解这个主题。
本文目录一览:- 如何在Spring Boot应用程序启动时启动H2 TCP服务器?(spring boot启动端口)
- java – spring-boot应用程序无法启动
- java – Spring-boot应用程序无法在docker内启动时启动
- java – 在SpringBoot应用程序启动时捕获Hibernate异常?
- java – 测试启动Spring-boot应用程序
如何在Spring Boot应用程序启动时启动H2 TCP服务器?(spring boot启动端口)
通过将以下行添加到SpringBootServletInitializer主方法中,可以在将应用程序作为Spring Boot应用程序运行时启动H2
TCP服务器(文件中的数据库):
@SpringBootApplicationpublic class NatiaApplication extends SpringBootServletInitializer { public static void main(String[] args) { Server.createTcpServer().start(); SpringApplication.run(NatiaApplication.class, args); }}
但是,如果我在Tomcat上运行WAR文件,则该文件将不起作用,因为未调用main方法。有没有更好的通用方法,如何在初始化bean之前在应用程序启动时启动H2
TCP服务器?我使用Flyway(autoconfig),它在“连接被拒绝:连接”失败,可能是因为服务器未运行。谢谢。
答案1
小编典典这个解决方案对我有用。如果该应用程序作为Spring
Boot应用程序运行,并且在Tomcat上运行,它将启动H2服务器。将H2服务器创建为Bean无效,因为Flyway
Bean是较早创建的,并且在“连接被拒绝”时失败。
@SpringBootApplication@Logpublic class NatiaApplication extends SpringBootServletInitializer { public static void main(String[] args) { startH2Server(); SpringApplication.run(NatiaApplication.class, args); } @Override protected SpringApplicationBuilder configure(SpringApplicationBuilder application) { startH2Server(); return application.sources(NatiaApplication.class); } private static void startH2Server() { try { Server h2Server = Server.createTcpServer().start(); if (h2Server.isRunning(true)) { log.info("H2 server was started and is running."); } else { throw new RuntimeException("Could not start H2 server."); } } catch (SQLException e) { throw new RuntimeException("Failed to start H2 server: ", e); } }}
java – spring-boot应用程序无法启动
的pom.xml
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> <modelVersion>4.0.0</modelVersion> <groupId>spring</groupId> <artifactId>app</artifactId> <version>0.0.1-SNAPSHOT</version> <packaging>jar</packaging> <name>app</name> <url>http://maven.apache.org</url> <properties> <start-class>com.spring.app.Application</start-class> <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> </properties> <parent> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-parent</artifactId> <version>1.1.8.RELEASE</version> </parent> <dependencies> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-web</artifactId> </dependency> </dependencies> </project>
Application.java
@Configuration @EnableAutoConfiguration @ComponentScan public class Application { public static void main(String[] args) { ApplicationContext ctx = SpringApplication.run(Application.class,args); System.out.println("Let's inspect the beans provided by Spring Boot:"); String[] beanNames = ctx.getBeanDeFinitionNames(); Arrays.sort(beanNames); for (String beanName : beanNames) { System.out.println(beanName); } } }
但是当我尝试用java -jar appname运行应用程序时,我得到错误:找不到主类:com.spring.app.Application.程序将退出,并在终端:线程“main”中的异常java.lang.NoClassDefFoundError:com / spring / app / Application.
我做错了什么?
解决方法
首先将start-class更改为您的应用程序类.
第二,将超酷的Spring Boot maven builder添加到你的pom中.
像这样的东西:
<?xml version="1.0" encoding="UTF-8"?> <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> <modelVersion>4.0.0</modelVersion> <groupId>com.sample</groupId> <artifactId>beanlist</artifactId> <version>1.0-SNAPSHOT</version> <properties> <start-class>com.sample.Application</start-class> <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> </properties> <parent> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-parent</artifactId> <version>1.1.8.RELEASE</version> </parent> <dependencies> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-web</artifactId> </dependency> </dependencies> <build> <plugins> <plugin> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-maven-plugin</artifactId> </plugin> </plugins> </build> </project
然后使用“mvn install”创建你的jar.你的代码运行得很好.
java – Spring-boot应用程序无法在docker内启动时启动
我在docker容器中运行一个简单的spring-boot应用程序.在启动时是否以java -jar MY_JAR.jar或mvn spring-boot:run开始运行应用程序将始终挂起以下点:
2014-12-22 23:26:58.957 INFO 1 --- [ost-startStop-1] o.s.b.c.embedded.FilterRegistrationBean : Mapping filter: 'hiddenHttpMethodFilter' to: [/*]
这是捕获,我只能在DigitalOcean(1cpu,1GB MEM)的Ubuntu 14.04盒子上重现这一点,即使它在容器内运行.在我的本地机器(mac)上一切正常.
Dockerfile:
FROM java:8
ADD target/MY_SERVICE-1.0-SNAPSHOT.jar /data/svc.jar
EXPOSE 8080
CMD ["java", "-jar", "/data/svc.jar"]
我试过的事情
>为JVM提供更多内存(占机器总数的75%)
>根据建议here安装已伪造的库
>每个其他版本的java我都可以得到我的动手
有什么建议么?
谢谢你的帮助.
整个日志(以–debug开头):
[Text Art Omitted]
:: Spring Boot :: (v1.1.10.RELEASE)
2014-12-22 19:22:58.375 INFO 20816 --- [ main] com.spectrom.uploadService.Main : Starting Main on spectrom-services with PID 20816 (/root/spectrom-upload-service/target/upload-service-1.0-SNAPSHOT.jar started by root in /root/spectrom-upload-service)
2014-12-22 19:22:58.392 DEBUG 20816 --- [ main] o.s.boot.SpringApplication : Loading source class com.spectrom.uploadService.Main
2014-12-22 19:22:58.671 DEBUG 20816 --- [ main] o.s.b.c.c.ConfigFileApplicationListener : Skipped config file 'file:./config/application.yaml' resource not found
2014-12-22 19:22:58.673 DEBUG 20816 --- [ main] o.s.b.c.c.ConfigFileApplicationListener : Skipped config file 'file:./config/application.properties' resource not found
2014-12-22 19:22:58.674 DEBUG 20816 --- [ main] o.s.b.c.c.ConfigFileApplicationListener : Skipped config file 'file:./config/application.yml' resource not found
2014-12-22 19:22:58.675 DEBUG 20816 --- [ main] o.s.b.c.c.ConfigFileApplicationListener : Skipped config file 'file:./application.yaml' resource not found
2014-12-22 19:22:58.675 DEBUG 20816 --- [ main] o.s.b.c.c.ConfigFileApplicationListener : Skipped config file 'file:./application.properties' resource not found
2014-12-22 19:22:58.676 DEBUG 20816 --- [ main] o.s.b.c.c.ConfigFileApplicationListener : Skipped config file 'file:./application.yml' resource not found
2014-12-22 19:22:58.677 DEBUG 20816 --- [ main] o.s.b.c.c.ConfigFileApplicationListener : Skipped config file 'classpath:/config/application.yaml' resource not found
2014-12-22 19:22:58.678 DEBUG 20816 --- [ main] o.s.b.c.c.ConfigFileApplicationListener : Skipped config file 'classpath:/config/application.properties' resource not found
2014-12-22 19:22:58.679 DEBUG 20816 --- [ main] o.s.b.c.c.ConfigFileApplicationListener : Skipped config file 'classpath:/config/application.yml' resource not found
2014-12-22 19:22:58.679 DEBUG 20816 --- [ main] o.s.b.c.c.ConfigFileApplicationListener : Skipped config file 'classpath:/application.yaml' resource not found
2014-12-22 19:22:58.680 DEBUG 20816 --- [ main] o.s.b.c.c.ConfigFileApplicationListener : Loaded config file 'classpath:/application.properties'
2014-12-22 19:22:58.681 DEBUG 20816 --- [ main] o.s.b.c.c.ConfigFileApplicationListener : Skipped config file 'classpath:/application.yml' resource not found
2014-12-22 19:22:58.693 INFO 20816 --- [ main] ationConfigEmbeddedWebApplicationContext : Refreshing org.springframework.boot.context.embedded.AnnotationConfigEmbeddedWebApplicationContext@ddd51a7: startup date [Mon Dec 22 19:22:58 EST 2014]; root of context hierarchy
2014-12-22 19:22:58.708 DEBUG 20816 --- [ main] ationConfigEmbeddedWebApplicationContext : Bean factory for org.springframework.boot.context.embedded.AnnotationConfigEmbeddedWebApplicationContext@ddd51a7: org.springframework.beans.factory.support.DefaultListablebeanfactory@47649f10: defining beans [org.springframework.context.annotation.internalConfigurationAnnotationProcessor,org.springframework.context.annotation.internalAutowiredAnnotationProcessor,org.springframework.context.annotation.internalrequiredAnnotationProcessor,org.springframework.context.annotation.internalCommonAnnotationProcessor,main]; root of factory hierarchy
2014-12-22 19:23:00.964 INFO 20816 --- [ main] o.s.b.f.s.DefaultListablebeanfactory : Overriding bean deFinition for bean 'beanNameViewResolver': 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]]
2014-12-22 19:23:02.480 DEBUG 20816 --- [ main] ationConfigEmbeddedWebApplicationContext : Unable to locate MessageSource with name 'messageSource': using default [org.springframework.context.support.DelegatingMessageSource@177df6c1]
2014-12-22 19:23:02.481 DEBUG 20816 --- [ main] ationConfigEmbeddedWebApplicationContext : Using ApplicationEventMulticaster [org.springframework.context.event.SimpleApplicationEventMulticaster@4ed304f3]
2014-12-22 19:23:03.647 DEBUG 20816 --- [ main] .t.TomcatEmbeddedServletContainerFactory : Code archive: /root/spectrom-upload-service/target/upload-service-1.0-SNAPSHOT.jar
2014-12-22 19:23:03.648 DEBUG 20816 --- [ main] .t.TomcatEmbeddedServletContainerFactory : Code archive: /root/spectrom-upload-service/target/upload-service-1.0-SNAPSHOT.jar
2014-12-22 19:23:03.648 DEBUG 20816 --- [ main] .t.TomcatEmbeddedServletContainerFactory : None of the document roots [src/main/webapp, public, static] point to a directory and will be ignored.
2014-12-22 19:23:03.691 INFO 20816 --- [ main] .t.TomcatEmbeddedServletContainerFactory : Server initialized with port: 8080
2014-12-22 19:23:04.855 INFO 20816 --- [ main] o.apache.catalina.core.StandardService : Starting service Tomcat
2014-12-22 19:23:04.856 INFO 20816 --- [ main] org.apache.catalina.core.StandardEngine : Starting Servlet Engine: Apache Tomcat/7.0.57
2014-12-22 19:23:05.008 INFO 20816 --- [ost-startStop-1] o.a.c.c.C.[Tomcat].[localhost].[/] : Initializing Spring embedded WebApplicationContext
2014-12-22 19:23:05.009 INFO 20816 --- [ost-startStop-1] o.s.web.context.ContextLoader : Root WebApplicationContext: initialization completed in 6326 ms
2014-12-22 19:23:06.928 INFO 20816 --- [ost-startStop-1] o.s.b.c.e.ServletRegistrationBean : Mapping servlet: 'dispatcherServlet' to [/]
2014-12-22 19:23:06.933 INFO 20816 --- [ost-startStop-1] o.s.b.c.embedded.FilterRegistrationBean : Mapping filter: 'hiddenHttpMethodFilter' to: [/*]
^ c之后:
^C2014-12-22 19:24:28.771 INFO 20816 --- [ Thread-2] ationConfigEmbeddedWebApplicationContext : Closing org.springframework.boot.context.embedded.AnnotationConfigEmbeddedWebApplicationContext@ddd51a7: startup date [Mon Dec 22 19:22:58 EST 2014]; root of context hierarchy
2014-12-22 19:24:28.815 WARN 20816 --- [ Thread-2] ationConfigEmbeddedWebApplicationContext : Exception thrown from LifecycleProcessor on context close
java.lang.IllegalStateException: LifecycleProcessor not initialized - call 'refresh' before invoking lifecycle methods via the context: org.springframework.boot.context.embedded.AnnotationConfigEmbeddedWebApplicationContext@ddd51a7: startup date [Mon Dec 22 19:22:58 EST 2014]; root of context hierarchy
at org.springframework.context.support.AbstractApplicationContext.getLifecycleProcessor(AbstractApplicationContext.java:359)
at org.springframework.context.support.AbstractApplicationContext.doClose(AbstractApplicationContext.java:890)
at org.springframework.boot.context.embedded.EmbeddedWebApplicationContext.doClose(EmbeddedWebApplicationContext.java:141)
at org.springframework.context.support.AbstractApplicationContext$1.run(AbstractApplicationContext.java:811)
挂起时的线程转储:
2014-12-23 01:09:58
Full thread dump Java HotSpot(TM) 64-Bit Server VM (25.25-b02 mixed mode):
"localhost-startStop-1" #13 daemon prio=5 os_prio=0 tid=0x00007f56c431a800 nid=0x12 runnable [0x00007f56e0bec000]
java.lang.Thread.State: RUNNABLE
at java.io.FileInputStream.readBytes(Native Method)
at java.io.FileInputStream.read(FileInputStream.java:246)
at sun.security.provider.SeedGenerator$URLSeedGenerator.getSeedBytes(SeedGenerator.java:539)
at sun.security.provider.SeedGenerator.generateSeed(SeedGenerator.java:144)
at sun.security.provider.SecureRandom$SeederHolder.<clinit>(SecureRandom.java:203)
at sun.security.provider.SecureRandom.engineNextBytes(SecureRandom.java:221)
- locked <0x00000000f10478f8> (a sun.security.provider.SecureRandom)
at java.security.SecureRandom.nextBytes(SecureRandom.java:457)
- locked <0x00000000f1047c18> (a java.security.SecureRandom)
at java.security.SecureRandom.next(SecureRandom.java:480)
at java.util.Random.nextInt(Random.java:329)
at org.apache.catalina.util.SessionIdGenerator.createSecureRandom(SessionIdGenerator.java:246)
at org.apache.catalina.util.SessionIdGenerator.getRandomBytes(SessionIdGenerator.java:183)
at org.apache.catalina.util.SessionIdGenerator.generateSessionId(SessionIdGenerator.java:153)
at org.apache.catalina.session.ManagerBase.startInternal(ManagerBase.java:573)
at org.apache.catalina.session.StandardManager.startInternal(StandardManager.java:485)
- locked <0x00000000f0fa82e0> (a org.apache.catalina.session.StandardManager)
at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:150)
- locked <0x00000000f0fa82e0> (a org.apache.catalina.session.StandardManager)
at org.apache.catalina.core.StandardContext.startInternal(StandardContext.java:5501)
- locked <0x00000000f68e5d68> (a org.springframework.boot.context.embedded.tomcat.TomcatEmbeddedContext)
at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:150)
- locked <0x00000000f68e5d68> (a org.springframework.boot.context.embedded.tomcat.TomcatEmbeddedContext)
at org.apache.catalina.core.ContainerBase$startChild.call(ContainerBase.java:1575)
at org.apache.catalina.core.ContainerBase$startChild.call(ContainerBase.java:1565)
at java.util.concurrent.FutureTask.run(FutureTask.java:266)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
at java.lang.Thread.run(Thread.java:745)
"Tomcat-startStop-1" #12 daemon prio=5 os_prio=0 tid=0x00007f56c8405000 nid=0x11 waiting on condition [0x00007f56f4103000]
java.lang.Thread.State: WAITING (parking)
at sun.misc.Unsafe.park(Native Method)
- parking to wait for <0x00000000f69aa980> (a java.util.concurrent.FutureTask)
at java.util.concurrent.locks.LockSupport.park(LockSupport.java:175)
at java.util.concurrent.FutureTask.awaitDone(FutureTask.java:429)
at java.util.concurrent.FutureTask.get(FutureTask.java:191)
at org.apache.catalina.core.ContainerBase.startInternal(ContainerBase.java:1123)
- locked <0x00000000f68505c0> (a org.apache.catalina.core.StandardHost)
at org.apache.catalina.core.StandardHost.startInternal(StandardHost.java:816)
- locked <0x00000000f68505c0> (a org.apache.catalina.core.StandardHost)
at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:150)
- locked <0x00000000f68505c0> (a org.apache.catalina.core.StandardHost)
at org.apache.catalina.core.ContainerBase$startChild.call(ContainerBase.java:1575)
at org.apache.catalina.core.ContainerBase$startChild.call(ContainerBase.java:1565)
at java.util.concurrent.FutureTask.run(FutureTask.java:266)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
at java.lang.Thread.run(Thread.java:745)
"DestroyJavaVM" #10 prio=5 os_prio=0 tid=0x00007f56f0009800 nid=0x7 waiting on condition [0x0000000000000000]
java.lang.Thread.State: RUNNABLE
"main" #9 prio=5 os_prio=0 tid=0x00007f56f0159800 nid=0x10 waiting on condition [0x00007f56f4cf0000]
java.lang.Thread.State: WAITING (parking)
at sun.misc.Unsafe.park(Native Method)
- parking to wait for <0x00000000f69aac08> (a java.util.concurrent.FutureTask)
at java.util.concurrent.locks.LockSupport.park(LockSupport.java:175)
at java.util.concurrent.FutureTask.awaitDone(FutureTask.java:429)
at java.util.concurrent.FutureTask.get(FutureTask.java:191)
at org.apache.catalina.core.ContainerBase.startInternal(ContainerBase.java:1123)
- locked <0x00000000f68d1648> (a org.apache.catalina.core.StandardEngine)
at org.apache.catalina.core.StandardEngine.startInternal(StandardEngine.java:300)
- locked <0x00000000f68d1648> (a org.apache.catalina.core.StandardEngine)
at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:150)
- locked <0x00000000f68d1648> (a org.apache.catalina.core.StandardEngine)
at org.apache.catalina.core.StandardService.startInternal(StandardService.java:443)
- locked <0x00000000f68d1648> (a org.apache.catalina.core.StandardEngine)
at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:150)
- locked <0x00000000f6850418> (a org.apache.catalina.core.StandardService)
at org.apache.catalina.core.StandardServer.startInternal(StandardServer.java:739)
- locked <0x00000000f6850590> (a [Lorg.apache.catalina.Service;)
at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:150)
- locked <0x00000000f683f5d8> (a org.apache.catalina.core.StandardServer)
at org.apache.catalina.startup.Tomcat.start(Tomcat.java:341)
at org.springframework.boot.context.embedded.tomcat.TomcatEmbeddedServletContainer.initialize(TomcatEmbeddedServletContainer.java:85)
- locked <0x00000000f68c4660> (a org.springframework.boot.context.embedded.tomcat.TomcatEmbeddedServletContainer)
at org.springframework.boot.context.embedded.tomcat.TomcatEmbeddedServletContainer.<init>(TomcatEmbeddedServletContainer.java:74)
at org.springframework.boot.context.embedded.tomcat.TomcatEmbeddedServletContainerFactory.getTomcatEmbeddedServletContainer(TomcatEmbeddedServletContainerFactory.java:377)
at org.springframework.boot.context.embedded.tomcat.TomcatEmbeddedServletContainerFactory.getEmbeddedServletContainer(TomcatEmbeddedServletContainerFactory.java:153)
at org.springframework.boot.context.embedded.EmbeddedWebApplicationContext.createEmbeddedServletContainer(EmbeddedWebApplicationContext.java:148)
- locked <0x00000000f5dd9708> (a org.springframework.boot.context.embedded.AnnotationConfigEmbeddedWebApplicationContext)
at org.springframework.boot.context.embedded.EmbeddedWebApplicationContext.onRefresh(EmbeddedWebApplicationContext.java:121)
at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:476)
- locked <0x00000000f5de2550> (a java.lang.Object)
at org.springframework.boot.context.embedded.EmbeddedWebApplicationContext.refresh(EmbeddedWebApplicationContext.java:109)
at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:691)
at org.springframework.boot.SpringApplication.run(SpringApplication.java:320)
at org.springframework.boot.SpringApplication.run(SpringApplication.java:952)
at org.springframework.boot.SpringApplication.run(SpringApplication.java:941)
at com.spectrom.uploadService.Main.main(Main.java:17)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:483)
at org.springframework.boot.loader.MainMethodRunner.run(MainMethodRunner.java:53)
at java.lang.Thread.run(Thread.java:745)
"Service Thread" #7 daemon prio=9 os_prio=0 tid=0x00007f56f00cd000 nid=0xe runnable [0x0000000000000000]
java.lang.Thread.State: RUNNABLE
"C1 CompilerThread1" #6 daemon prio=9 os_prio=0 tid=0x00007f56f00ca000 nid=0xd waiting on condition [0x0000000000000000]
java.lang.Thread.State: RUNNABLE
"C2 CompilerThread0" #5 daemon prio=9 os_prio=0 tid=0x00007f56f00c8000 nid=0xc waiting on condition [0x0000000000000000]
java.lang.Thread.State: RUNNABLE
"Signal dispatcher" #4 daemon prio=9 os_prio=0 tid=0x00007f56f00c6000 nid=0xb waiting on condition [0x0000000000000000]
java.lang.Thread.State: RUNNABLE
"Finalizer" #3 daemon prio=8 os_prio=0 tid=0x00007f56f009a000 nid=0xa in Object.wait() [0x00007f56f5500000]
java.lang.Thread.State: WAITING (on object monitor)
at java.lang.Object.wait(Native Method)
- waiting on <0x00000000f5bb8068> (a java.lang.ref.ReferenceQueue$Lock)
at java.lang.ref.ReferenceQueue.remove(ReferenceQueue.java:142)
- locked <0x00000000f5bb8068> (a java.lang.ref.ReferenceQueue$Lock)
at java.lang.ref.ReferenceQueue.remove(ReferenceQueue.java:158)
at java.lang.ref.Finalizer$FinalizerThread.run(Finalizer.java:209)
"Reference Handler" #2 daemon prio=10 os_prio=0 tid=0x00007f56f0097800 nid=0x9 in Object.wait() [0x00007f56f5601000]
java.lang.Thread.State: WAITING (on object monitor)
at java.lang.Object.wait(Native Method)
- waiting on <0x00000000f5bb8220> (a java.lang.ref.Reference$Lock)
at java.lang.Object.wait(Object.java:502)
at java.lang.ref.Reference$ReferenceHandler.run(Reference.java:157)
- locked <0x00000000f5bb8220> (a java.lang.ref.Reference$Lock)
"VM Thread" os_prio=0 tid=0x00007f56f0090800 nid=0x8 runnable
"VM Periodic Task Thread" os_prio=0 tid=0x00007f56f00dc800 nid=0xf waiting on condition
JNI global references: 29
Heap
def new generation total 13696K, used 12232K [0x00000000f2014-12-22 23:26:58.957 INFO 1 --- [ost-startStop-1] o.s.b.c.embedded.FilterRegistrationBean : Mapping filter: 'hiddenHttpMethodFilter' to: [/*]
00, 0x00000000f14d0000, 0x00000000f5950000)
eden space 12224K, 88% used [0x00000000f
2014-12-22 23:26:58.957 INFO 1 --- [ost-startStop-1] o.s.b.c.embedded.FilterRegistrationBean : Mapping filter: 'hiddenHttpMethodFilter' to: [/*]
00, 0x00000000f1082050, 0x00000000f11f0000)
from space 1472K, 100% used [0x00000000f11f0000, 0x00000000f1360000, 0x00000000f1360000)
to space 1472K, 0% used [0x00000000f1360000, 0x00000000f1360000, 0x00000000f14d0000)
tenured generation total 30240K, used 20916K [0x00000000f5950000, 0x00000000f76d8000, 0x0000000100000000)
the space 30240K, 69% used [0x00000000f5950000, 0x00000000f6dbd1b0, 0x00000000f6dbd200, 0x00000000f76d8000)
Metaspace used 23431K, capacity 23620K, committed 23728K, reserved 1071104K
class space used 2909K, capacity 2974K, committed 2992K, reserved 1048576K
解决方法:
得到它了!一旦我安装在主机上,该过程立即向前移动,并且弹簧启动正常.一旦我对docker如何与主机上的hasged交互进行更多研究,我将发布更多内容.
总之,在主机上发出的以下命令将解决问题:
apt-get install haveged -y
如果有人对此有详细的了解,请随时发布!
我目前还不了解的是,为什么主机需要额外的代码,并且所有东西都没有在docker容器中被隔离.
java – 在SpringBoot应用程序启动时捕获Hibernate异常?
但是,在数据库错误(凭据无效,数据库无法访问等)的情况下,我找不到一种在启动时捕获Hibernate异常的简洁方法.
我想我可以捕获所有BeanCreationException并检查根本原因,但这似乎是一个非常黑客:
ConfigurableApplicationContext context; try { SpringApplication app = new SpringApplication(Application.class); context = app.run(args); } catch (Exception e) { // check if it is a DB error. if( ExceptionUtils.getRootCause(e) instanceof( HibernateException ) ){ System.out.println( "You are having trouble with the DB: " + ExceptionUtils.getRootCauseMessage(e) ); } } finally{ // finished so close the context if( context != null ) context.close(); }
在不失去使用自动配置的能力的情况下,是否有更干净/更简洁的方法?另外,如果没有解析错误消息,有没有办法确定Hibernate / DB错误是什么(即:无效的信用证,未经验证的数据库等).
解决方法
https://docs.jboss.org/hibernate/orm/4.3/javadocs/org/hibernate/exception/JDBCConnectionException.html
java – 测试启动Spring-boot应用程序
@WebIntegrationTest @RunWith(SpringJUnit4ClassRunner.class) @SpringApplicationConfiguration(classes = SpringTestDemoApp.class) public class SpringTest { @Test public void test() { // Test http://localhost:8080/ (with Selenium) } }
使用spring-boot 1.3.3.RELEASE一切正常.尽管如此,注释@WebIntegrationTest和@SpringApplicationConfiguration已在spring-boot 1.5.2.RELEASE中删除.我试图将代码重构为新版本,但我无法做到.通过以下测试,我的应用程序在测试之前未启动,http://localhost:8080返回404:
@RunWith(springrunner.class) @SpringBoottest(classes = SpringTestDemoApp.class) @WebAppConfiguration public class SpringTest { @Test public void test() { // The same test than before } }
如何重构我的测试以使其在spring-boot 1.5中工作?
解决方法
> NONE只会创建spring bean而不是任何模拟servlet环境.
> MOCK将创建spring bean和模拟servlet环境.
> RANDOM_PORT将在随机端口上启动实际的servlet容器;这可以使用@LocalServerPort自动装配.
> DEFINED_PORT将获取属性中定义的端口并使用它启动服务器.
如果未定义任何webEnvironment,则默认值为RANDOM_PORT.所以应用程序可能会在不同的端口为您启动.
尝试将其覆盖为DEFINED_PORT,或尝试自动装配端口号并尝试在该端口上运行测试.
关于如何在Spring Boot应用程序启动时启动H2 TCP服务器?和spring boot启动端口的介绍已经告一段落,感谢您的耐心阅读,如果想了解更多关于java – spring-boot应用程序无法启动、java – Spring-boot应用程序无法在docker内启动时启动、java – 在SpringBoot应用程序启动时捕获Hibernate异常?、java – 测试启动Spring-boot应用程序的相关信息,请在本站寻找。
本文标签: