trap Spring context close error - spring

I have a spring Integration project using spring-hadoop.
I have an Hbase template as follows,
<beans:bean id="fsh" class="org.springframework.data.hadoop.fs.FsShell">
</beans:bean>
<beans:bean id="hbaseTemplate"
class="org.springframework.data.hadoop.hbase.HbaseTemplate">
<beans:property name="configuration" ref="hdpConfiguration" />
</beans:bean>
Now, when I shutdown the app and the context at the end, it throws a strange error,
o.a.h.hbase.client.HConnectionManager : Connection not found in the list, can't delete it (connection key=HConnectionKey{properties={hbase.zookeeper.quorum=xxx.com,xxx.com, hbase.rpc.timeout=60000, hbase.client.prefetch.limit=10, hbase.zookeeper.property.clientPort=2181, zookeeper.znode.parent=/hbase-secure, hbase.client.retries.number=35, hbase.client.pause=100}, username='xyz#PQR.COM'}). May be the key was modified?
As I understand, this was an innocuous error and was thrown even in Hadoop 1.x
I have migrated to Hadoop 2.x and Spring-Hadoop-2.0.4
But now, spring throws an Exception which earlier was not thrown,
java.lang.Exception: null
at org.apache.hadoop.hbase.client.HConnectionManager.deleteConnection(HConnectionManager.java:488)
at org.apache.hadoop.hbase.client.HConnectionManager.deleteConnection(HConnectionManager.java:424)
at org.springframework.data.hadoop.hbase.HbaseConfigurationFactoryBean.destroy(HbaseConfigurationFactoryBean.java:80)
at org.springframework.beans.factory.support.DisposableBeanAdapter.destroy(DisposableBeanAdapter.java:258)
at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.destroyBean(DefaultSingletonBeanRegistry.java:578)
at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.destroySingleton(DefaultSingletonBeanRegistry.java:554)
at org.springframework.beans.factory.support.DefaultListableBeanFactory.destroySingleton(DefaultListableBeanFactory.java:907)
at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.destroySingletons(DefaultSingletonBeanRegistry.java:523)
at org.springframework.beans.factory.support.DefaultListableBeanFactory.destroySingletons(DefaultListableBeanFactory.java:914)
at org.springframework.context.support.AbstractApplicationContext.destroyBeans(AbstractApplicationContext.java:908)
at org.springframework.context.support.AbstractApplicationContext.doClose(AbstractApplicationContext.java:884)
at org.springframework.context.support.AbstractApplicationContext$1.run(AbstractApplicationContext.java:804)
2015-01-22 14:58:20.168 INFO --- [ Thread-11] o.s.s.concurrent.ThreadPoolTaskExecutor : Shutting down ExecutorService
2015-01-22 14:58:20.170 INFO --- [ Thread-11] o.s.s.c.ThreadPoolTaskScheduler : Shutting down ExecutorService 'taskScheduler'
2015-01-22 14:58:20.175 INFO --- [ Thread-2] j.LocalContainerEntityManagerFactoryBean : Closing JPA EntityManagerFactory for persistence unit 'default'
Question, how can I trap this error so that it's not shown to the user...
Thanks for any insight.

I was able to resolve the error, simply by setting delete-connection to false, (default is 'true')
<hbase-configuration configration-ref="hdpConfiguration" delete-connection="false"/>

Related

Bugs started how do I fix? Error (Spring Boot + Thymeleaf)

ERROR 8164 --- [ restartedMain] com.zaxxer.hikari.pool.HikariPool : HikariPool-1 - Exception during pool initialization.
2021-01-24 16:55:32.459 ERROR 8164 --- [ restartedMain] j.LocalContainerEntityManagerFactoryBean : Failed to initialize JPA EntityManagerFactory: Unable to create requested service [org.hibernate.engine.jdbc.env.spi.JdbcEnvironment]
2021-01-24 16:55:32.606 ERROR 8164 --- [ restartedMain] o.s.boot.SpringApplication : Application run failed
Bugs started how do I fix?

Spring shell blocks tests

When I added spring shell to project
<dependency>
<groupId>org.springframework.shell</groupId>
<artifactId>spring-shell-starter</artifactId>
<version>2.0.1.RELEASE</version>
</dependency>
tests began to hangs and never ends. After stop I see in logs
2020-02-22 20:00:14.271 INFO 9812 --- [ main] o.s.s.c.ThreadPoolTaskScheduler : Initializing ExecutorService 'taskScheduler'
2020-02-22 20:00:14.933 WARN 9812 --- [ main] org.jline : Unable to create a system terminal, creating a dumb terminal (enable debug logging for more information)
2020-02-22 20:00:15.229 INFO 9812 --- [ main] o.s.a.r.c.CachingConnectionFactory : Attempting to connect to: [192.168.1.10:5672]
2020-02-22 20:00:15.312 INFO 9812 --- [ main] o.s.a.r.c.CachingConnectionFactory : Created new connection: rabbitConnectionFactory#4c32d208:0/SimpleConnection#608c36a6 [delegate=amqp://admin#192.168.1.10:5672/, localPort= 65404]
2020-02-22 20:00:15.401 INFO 9812 --- [ main] c.umbrella.app.BackendApplicationTests : Started BackendApplicationTests in 12.969 seconds (JVM running for 14.251)
Process finished with exit code -1
shell:>
The problem reproduces when I run tests from IDE and mvn.
How to avoid problem with tests?
I found solution, it needs to add next properties to each test:
#SpringBootTest(properties = {
InteractiveShellApplicationRunner.SPRING_SHELL_INTERACTIVE_ENABLED + "=false",
ScriptShellApplicationRunner.SPRING_SHELL_SCRIPT_ENABLED + "=false"
})
In Spring Shell 2:
#SpringBootTest(properties = "spring.shell.interactive.enabled=false")

spring-boot-starter-quartz jdbc example

Starting with spring-boot 2.x.x they started offering spring-boot-starter-quartz which is great! Out of the box it does an in-memory store. I want to change it to be a clustered environment but I'm having issues with the configuration I think mostly because I need to put the qrtz_ tables in a different schema than my default data source. Does anyone have an example of using an alternate datasource? I'm currently attempting to set the properties field (as you can see below) but its like they are not being picked up by the configuration bean. Any help is appreciated.
Configuration
spring:
quartz:
job-store-type: jdbc
jdbc:
initialize-schema: never
properties:
scheduler:
instanceName : MyClusteredScheduler
instanceId : AUTO
threadPool:
class : org.quartz.simpl.SimpleThreadPool
threadCount : 25
threadPriority : 5
jobStore:
misfireThreshold : 60000
class : org.quartz.impl.jdbcjobstore.JobStoreTX
driverDelegateClass : org.quartz.impl.jdbcjobstore.StdJDBCDelegate
useProperties : false
dataSource : myDS
tablePrefix : QRTZ_
isClustered : true
clusterCheckinInterval : 20000
dataSource:
myDS:
driver : com.mysql.jdbc.Driver
URL : jdbc:mysql://127.0.0.1:3306/quartz
user : removed
password : removed
maxConnections : 5
validationQuery : select 0 from dual
Output from log
2017-11-06 13:33:02.853 INFO 7082 --- [ main] org.quartz.core.QuartzScheduler : Quartz Scheduler v.2.3.0 created.
2017-11-06 13:33:02.856 INFO 7082 --- [ main] o.s.s.quartz.LocalDataSourceJobStore : Using db table-based data access locking (synchronization).
2017-11-06 13:33:02.858 INFO 7082 --- [ main] o.s.s.quartz.LocalDataSourceJobStore : JobStoreCMT initialized.
2017-11-06 13:33:02.859 INFO 7082 --- [ main] org.quartz.core.QuartzScheduler : Scheduler meta-data: Quartz Scheduler (v2.3.0) 'quartzScheduler' with instanceId 'NON_CLUSTERED'
Scheduler class: 'org.quartz.core.QuartzScheduler' - running locally.
NOT STARTED.
Currently in standby mode.
Number of jobs executed: 0
Using thread pool 'org.quartz.simpl.SimpleThreadPool' - with 10 threads.
Using job-store 'org.springframework.scheduling.quartz.LocalDataSourceJobStore' - which supports persistence. and is not clustered.
2017-11-06 13:33:02.859 INFO 7082 --- [ main] org.quartz.impl.StdSchedulerFactory : Quartz scheduler 'quartzScheduler' initialized from an externally provided properties instance.
2017-11-06 13:33:02.860 INFO 7082 --- [ main] org.quartz.impl.StdSchedulerFactory : Quartz scheduler version: 2.3.0
2017-11-06 13:33:02.860 INFO 7082 --- [ main] org.quartz.core.QuartzScheduler : JobFactory set to: org.springframework.boot.autoconfigure.quartz.AutowireCapableBeanJobFactory#21132086
2017-11-06 13:33:03.214 INFO 7082 --- [ main] o.s.j.e.a.AnnotationMBeanExporter : Registering beans for JMX exposure on startup
2017-11-06 13:33:03.216 INFO 7082 --- [ main] o.s.j.e.a.AnnotationMBeanExporter : Bean with name 'dataSource' has been autodetected for JMX exposure
2017-11-06 13:33:03.223 INFO 7082 --- [ main] o.s.j.e.a.AnnotationMBeanExporter : Located MBean 'dataSource': registering with JMX server as MBean [com.zaxxer.hikari:name=dataSource,type=HikariDataSource]
2017-11-06 13:33:03.227 INFO 7082 --- [ main] o.s.c.support.DefaultLifecycleProcessor : Starting beans in phase 2147483647
2017-11-06 13:33:03.227 INFO 7082 --- [ main] o.s.s.quartz.SchedulerFactoryBean : Starting Quartz Scheduler now
2017-11-06 13:33:05.250 WARN 7082 --- [ main] ConfigServletWebServerApplicationContext : Exception encountered during context initialization - cancelling refresh attempt: org.springframework.context.ApplicationContextException: Failed to start bean 'quartzScheduler'; nested exception is org.springframework.scheduling.SchedulingException: Could not start Quartz Scheduler; nested exception is org.quartz.SchedulerConfigException: Failure occured during job recovery. [See nested exception: org.quartz.impl.jdbcjobstore.LockException: Failure obtaining db row lock: No database selected [See nested exception: java.sql.SQLException: No database selected]]
2017-11-06 13:33:05.250 INFO 7082 --- [ main] o.s.s.quartz.SchedulerFactoryBean : Shutting down Quartz Scheduler
2017-11-06 13:33:05.251 INFO 7082 --- [ main] org.quartz.core.QuartzScheduler : Scheduler quartzScheduler_$_NON_CLUSTERED shutting down.
2017-11-06 13:33:05.251 INFO 7082 --- [ main] org.quartz.core.QuartzScheduler : Scheduler quartzScheduler_$_NON_CLUSTERED paused.
2017-11-06 13:33:05.251 INFO 7082 --- [ main] org.quartz.core.QuartzScheduler : Scheduler quartzScheduler_$_NON_CLUSTERED shutdown complete.
2017-11-06 13:33:05.252 INFO 7082 --- [ main] o.s.j.e.a.AnnotationMBeanExporter : Unregistering JMX-exposed beans on shutdown
2017-11-06 13:33:05.253 INFO 7082 --- [ main] o.s.j.e.a.AnnotationMBeanExporter : Unregistering JMX-exposed beans
2017-11-06 13:33:05.254 INFO 7082 --- [ main] j.LocalContainerEntityManagerFactoryBean : Closing JPA EntityManagerFactory for persistence unit 'default'
2017-11-06 13:33:05.255 INFO 7082 --- [ main] com.zaxxer.hikari.HikariDataSource : testdb - Shutdown initiated...
2017-11-06 13:33:05.264 INFO 7082 --- [ main] com.zaxxer.hikari.HikariDataSource : testdb - Shutdown completed.
2017-11-06 13:33:05.265 INFO 7082 --- [ main] o.apache.catalina.core.StandardService : Stopping service [Tomcat]
2017-11-06 13:33:05.283 INFO 7082 --- [ main] utoConfigurationReportLoggingInitializer :
Error starting ApplicationContext. To display the auto-configuration report re-run your application with 'debug' enabled.
2017-11-06 13:33:05.293 ERROR 7082 --- [ main] o.s.boot.SpringApplication : Application startup failed
org.springframework.context.ApplicationContextException: Failed to start bean 'quartzScheduler'; nested exception is org.springframework.scheduling.SchedulingException: Could not start Quartz Scheduler; nested exception is org.quartz.SchedulerConfigException: Failure occured during job recovery. [See nested exception: org.quartz.impl.jdbcjobstore.LockException: Failure obtaining db row lock: No database selected [See nested exception: java.sql.SQLException: No database selected]]
at org.springframework.context.support.DefaultLifecycleProcessor.doStart(DefaultLifecycleProcessor.java:186) ~[spring-context-5.0.0.RELEASE.jar:5.0.0.RELEASE]
at org.springframework.context.support.DefaultLifecycleProcessor.access$200(DefaultLifecycleProcessor.java:52) ~[spring-context-5.0.0.RELEASE.jar:5.0.0.RELEASE]
at org.springframework.context.support.DefaultLifecycleProcessor$LifecycleGroup.start(DefaultLifecycleProcessor.java:358) ~[spring-context-5.0.0.RELEASE.jar:5.0.0.RELEASE]
at org.springframework.context.support.DefaultLifecycleProcessor.startBeans(DefaultLifecycleProcessor.java:159) ~[spring-context-5.0.0.RELEASE.jar:5.0.0.RELEASE]
at org.springframework.context.support.DefaultLifecycleProcessor.onRefresh(DefaultLifecycleProcessor.java:123) ~[spring-context-5.0.0.RELEASE.jar:5.0.0.RELEASE]
at org.springframework.context.support.AbstractApplicationContext.finishRefresh(AbstractApplicationContext.java:884) ~[spring-context-5.0.0.RELEASE.jar:5.0.0.RELEASE]
at org.springframework.boot.web.servlet.context.ServletWebServerApplicationContext.finishRefresh(ServletWebServerApplicationContext.java:143) ~[spring-boot-2.0.0.M5.jar:2.0.0.M5]
at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:552) ~[spring-context-5.0.0.RELEASE.jar:5.0.0.RELEASE]
at org.springframework.boot.web.servlet.context.ServletWebServerApplicationContext.refresh(ServletWebServerApplicationContext.java:122) ~[spring-boot-2.0.0.M5.jar:2.0.0.M5]
at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:750) [spring-boot-2.0.0.M5.jar:2.0.0.M5]
at org.springframework.boot.SpringApplication.refreshContext(SpringApplication.java:386) [spring-boot-2.0.0.M5.jar:2.0.0.M5]
at org.springframework.boot.SpringApplication.run(SpringApplication.java:327) [spring-boot-2.0.0.M5.jar:2.0.0.M5]
at org.springframework.boot.SpringApplication.run(SpringApplication.java:1245) [spring-boot-2.0.0.M5.jar:2.0.0.M5]
at org.springframework.boot.SpringApplication.run(SpringApplication.java:1233) [spring-boot-2.0.0.M5.jar:2.0.0.M5]
at com.tci.reader.incident.parser.IncidentParserApplication.main(IncidentParserApplication.java:18) [classes/:na]
Caused by: org.springframework.scheduling.SchedulingException: Could not start Quartz Scheduler; nested exception is org.quartz.SchedulerConfigException: Failure occured during job recovery. [See nested exception: org.quartz.impl.jdbcjobstore.LockException: Failure obtaining db row lock: No database selected [See nested exception: java.sql.SQLException: No database selected]]
at org.springframework.scheduling.quartz.SchedulerFactoryBean.start(SchedulerFactoryBean.java:738) ~[spring-context-support-5.0.0.RELEASE.jar:5.0.0.RELEASE]
at org.springframework.context.support.DefaultLifecycleProcessor.doStart(DefaultLifecycleProcessor.java:183) ~[spring-context-5.0.0.RELEASE.jar:5.0.0.RELEASE]
... 14 common frames omitted
Caused by: org.quartz.SchedulerConfigException: Failure occured during job recovery.
at org.quartz.impl.jdbcjobstore.JobStoreSupport.schedulerStarted(JobStoreSupport.java:697) ~[quartz-2.3.0.jar:na]
at org.quartz.core.QuartzScheduler.start(QuartzScheduler.java:539) ~[quartz-2.3.0.jar:na]
at org.quartz.impl.StdScheduler.start(StdScheduler.java:142) ~[quartz-2.3.0.jar:na]
at org.springframework.scheduling.quartz.SchedulerFactoryBean.startScheduler(SchedulerFactoryBean.java:664) ~[spring-context-support-5.0.0.RELEASE.jar:5.0.0.RELEASE]
at org.springframework.scheduling.quartz.SchedulerFactoryBean.start(SchedulerFactoryBean.java:735) ~[spring-context-support-5.0.0.RELEASE.jar:5.0.0.RELEASE]
... 15 common frames omitted
Caused by: org.quartz.impl.jdbcjobstore.LockException: Failure obtaining db row lock: No database selected
at org.quartz.impl.jdbcjobstore.StdRowLockSemaphore.executeSQL(StdRowLockSemaphore.java:157) ~[quartz-2.3.0.jar:na]
at org.quartz.impl.jdbcjobstore.DBSemaphore.obtainLock(DBSemaphore.java:113) ~[quartz-2.3.0.jar:na]
at org.quartz.impl.jdbcjobstore.JobStoreSupport.executeInNonManagedTXLock(JobStoreSupport.java:3842) ~[quartz-2.3.0.jar:na]
at org.quartz.impl.jdbcjobstore.JobStoreSupport.recoverJobs(JobStoreSupport.java:839) ~[quartz-2.3.0.jar:na]
at org.quartz.impl.jdbcjobstore.JobStoreSupport.schedulerStarted(JobStoreSupport.java:695) ~[quartz-2.3.0.jar:na]
... 19 common frames omitted
Caused by: java.sql.SQLException: No database selected
at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:964) ~[mysql-connector-java-5.1.44.jar:5.1.44]
at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:3973) ~[mysql-connector-java-5.1.44.jar:5.1.44]
at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:3909) ~[mysql-connector-java-5.1.44.jar:5.1.44]
at com.mysql.jdbc.MysqlIO.sendCommand(MysqlIO.java:2527) ~[mysql-connector-java-5.1.44.jar:5.1.44]
at com.mysql.jdbc.MysqlIO.sqlQueryDirect(MysqlIO.java:2680) ~[mysql-connector-java-5.1.44.jar:5.1.44]
at com.mysql.jdbc.ConnectionImpl.execSQL(ConnectionImpl.java:2487) ~[mysql-connector-java-5.1.44.jar:5.1.44]
at com.mysql.jdbc.PreparedStatement.executeInternal(PreparedStatement.java:1858) ~[mysql-connector-java-5.1.44.jar:5.1.44]
at com.mysql.jdbc.PreparedStatement.executeQuery(PreparedStatement.java:1966) ~[mysql-connector-java-5.1.44.jar:5.1.44]
at com.zaxxer.hikari.pool.ProxyPreparedStatement.executeQuery(ProxyPreparedStatement.java:52) ~[HikariCP-2.7.2.jar:na]
at com.zaxxer.hikari.pool.HikariProxyPreparedStatement.executeQuery(HikariProxyPreparedStatement.java) ~[HikariCP-2.7.2.jar:na]
at org.quartz.impl.jdbcjobstore.StdRowLockSemaphore.executeSQL(StdRowLockSemaphore.java:96) ~[quartz-2.3.0.jar:na]
... 23 common frames omitted
You have to use the correct properties for the quartz properties.
Your properties are missing ...org.quartz...
For the none-yml notation, try this for the threadCount:
spring.quartz.properties.org.quartz.threadPool.threadCount=25
For the yml notation:
Add two layers under the 'properties', e.g.
spring:
quartz:
properties:
org:
quartz:
threadPool:
threadCount : 25
Application.yml file:
spring:
jpa:
hibernate:
ddl-auto: none
datasource:
url: jdbc:mysql://127.0.0.1:3306/Quartz
username: Your Username
password: Your Password
quartz:
scheduler:
instanceName: Scheduler
threadPool:
class: org.quartz.simpl.SimpleThreadPool
threadCount: 3
context:
key:
QuartzTopic: QuartzPorperties
jobStore:
driver: com.mysql.jdbc.Driver
class: org.quartz.impl.jdbcjobstore.JobStoreTX
driverDelegateClass: org.quartz.impl.jdbcjobstore.StdJDBCDelegate
misfireThreshold: 6000
tablePrefix: QRTZ_
Next create a Configuration class which reads these properties from the yml file and then creates a Scheduler Bean:
#Configuration
public class SchedulerConfig {
private final Logger logger = LoggerFactory.getLogger(this.getClass());
#Value("${quartz.scheduler.instanceName}")
private String instanceName;
#Value("${quartz.threadPool.class}")
private String threadClass;
#Value("${quartz.threadPool.threadCount}")
private String threadCount;
#Value("${quartz.context.key.QuartzTopic}")
private String quartzTopic;
#Value("${quartz.jobStore.class}")
private String jobStoreClass;
#Value("${quartz.jobStore.driverDelegateClass}")
private String driverDelegateClass;
#Value("${quartz.jobStore.misfireThreshold}")
private String misfireThreshold;
#Value("${quartz.jobStore.tablePrefix}")
private String tablePrefix;
#Value("${quartz.jobStore.driver}")
private String dataSourceDriver;
#Value("${spring.datasource.url}")
private String dataSourceUrl;
#Value("${spring.datasource.username}")
private String dataSourceUsername;
#Value("${spring.datasource.password}")
private String databasePassword;
#Bean({"Scheduler"})
public Scheduler getScheduler() {
Scheduler scheduler = null;
try {
StdSchedulerFactory factory = new StdSchedulerFactory();
Properties props = new Properties();
props.put("org.quartz.scheduler.instanceName", instanceName);
props.put("org.quartz.threadPool.class", threadClass);
props.put("org.quartz.threadPool.threadCount", threadCount);
props.put("org.quartz.context.key.QuartzTopic", quartzTopic);
props.put("org.quartz.jobStore.class", jobStoreClass);
props.put("org.quartz.jobStore.driverDelegateClass", driverDelegateClass);
props.put("quartz.jobStore.misfireThreshold", misfireThreshold);
props.put("org.quartz.jobStore.tablePrefix", tablePrefix);
props.put("org.quartz.jobStore.dataSource", "myDS");
props.put("org.quartz.dataSource.myDS.driver", dataSourceDriver);
props.put("org.quartz.dataSource.myDS.URL", dataSourceUrl);
props.put("org.quartz.dataSource.myDS.user", dataSourceUsername);
props.put("org.quartz.dataSource.myDS.password", databasePassword);
props.put("org.quartz.dataSource.myDS.maxConnections", "10");
factory.initialize(props);
scheduler = factory.getScheduler();
scheduler.start();
scheduler.resumeAll(); // This is to resume the entire scheduler when a new build is deployed
} catch (Exception e) {
logger.error("{} - SchedulerConfig class - getScheduler() - Error creating Scheduler instance: {}",
appName, e);
}
return scheduler;
}
}
Finally, use the Bean as below in any class you want:
#Autowired
private Scheduler scheduler;

JHipster and mongodb : Error creating bean with name 'mongobee'

I am rather new to JHipster and I followed their instructions in order to create a new app.
The app was created, imported into STS as a Maven project and I updated it.
However as soon as I try to start it via the Boot Dashboard I get this output :
2016-12-07 16:43:14.887 INFO 6396 --- [ restartedMain] com.mycompany.myapp.MdcApp : Starting MdcApp on PC981 with PID 6396 (C:\Users\lvuillaume\Desktop\mdc\target\classes started by lvuillaume in C:\Users\lvuillaume\Desktop\mdc)
2016-12-07 16:43:14.890 DEBUG 6396 --- [ restartedMain] com.mycompany.myapp.MdcApp : Running with Spring Boot v1.4.2.RELEASE, Spring v4.3.4.RELEASE
2016-12-07 16:43:14.891 INFO 6396 --- [ restartedMain] com.mycompany.myapp.MdcApp : The following profiles are active: swagger,dev
2016-12-07 16:43:14.972 DEBUG 6396 --- [kground-preinit] org.jboss.logging : Logging Provider: org.jboss.logging.Slf4jLoggerProvider found via system property
2016-12-07 16:43:18.499 DEBUG 6396 --- [ restartedMain] c.m.myapp.config.AsyncConfiguration : Creating Async Task Executor
2016-12-07 16:43:19.041 DEBUG 6396 --- [ restartedMain] c.m.myapp.config.MetricsConfiguration : Registering JVM gauges
2016-12-07 16:43:19.059 DEBUG 6396 --- [ restartedMain] c.m.myapp.config.MetricsConfiguration : Initializing Metrics JMX reporting
2016-12-07 16:43:19.960 WARN 6396 --- [ restartedMain] io.undertow.websockets.jsr : UT026009: XNIO worker was not set on WebSocketDeploymentInfo, the default worker will be used
2016-12-07 16:43:19.961 WARN 6396 --- [ restartedMain] io.undertow.websockets.jsr : UT026010: Buffer pool was not set on WebSocketDeploymentInfo, the default pool will be used
2016-12-07 16:43:20.436 INFO 6396 --- [ restartedMain] c.mycompany.myapp.config.WebConfigurer : Web application configuration, using profiles: [swagger, dev]
2016-12-07 16:43:20.437 DEBUG 6396 --- [ restartedMain] c.mycompany.myapp.config.WebConfigurer : Initializing Metrics registries
2016-12-07 16:43:20.442 DEBUG 6396 --- [ restartedMain] c.mycompany.myapp.config.WebConfigurer : Registering Metrics Filter
2016-12-07 16:43:20.442 DEBUG 6396 --- [ restartedMain] c.mycompany.myapp.config.WebConfigurer : Registering Metrics Servlet
2016-12-07 16:43:20.445 INFO 6396 --- [ restartedMain] c.mycompany.myapp.config.WebConfigurer : Web application fully configured
2016-12-07 16:43:20.491 INFO 6396 --- [ restartedMain] com.mycompany.myapp.MdcApp : Running with Spring profile(s) : [swagger, dev]
2016-12-07 16:43:20.579 DEBUG 6396 --- [ restartedMain] c.m.myapp.config.CacheConfiguration : No cache
2016-12-07 16:43:24.805 DEBUG 6396 --- [ restartedMain] c.m.m.c.apidoc.SwaggerConfiguration : Starting Swagger
2016-12-07 16:43:24.816 DEBUG 6396 --- [ restartedMain] c.m.m.c.apidoc.SwaggerConfiguration : Started Swagger in 10 ms
2016-12-07 16:43:24.849 DEBUG 6396 --- [ restartedMain] c.m.myapp.config.DatabaseConfiguration : Configuring Mongobee
2016-12-07 16:43:24.854 INFO 6396 --- [ restartedMain] com.github.mongobee.Mongobee : Mongobee has started the data migration sequence..
2016-12-07 16:43:54.876 WARN 6396 --- [ restartedMain] ationConfigEmbeddedWebApplicationContext : Exception encountered during context initialization - cancelling refresh attempt: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'mongobee' defined in class path resource [com/mycompany/myapp/config/DatabaseConfiguration.class]: Invocation of init method failed; nested exception is com.mongodb.MongoTimeoutException: Timed out after 30000 ms while waiting for a server that matches ReadPreferenceServerSelector{readPreference=primary}. Client view of cluster state is {type=UNKNOWN, servers=[{address=localhost:27017, type=UNKNOWN, state=CONNECTING, exception={com.mongodb.MongoSocketOpenException: Exception opening socket}, caused by {java.net.ConnectException: Connection refused: connect}}]
2016-12-07 16:43:54.883 INFO 6396 --- [ restartedMain] c.m.myapp.config.CacheConfiguration : Closing Cache Manager
2016-12-07 16:43:54.905 ERROR 6396 --- [ restartedMain] o.s.boot.SpringApplication : Application startup failed
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'mongobee' defined in class path resource [com/mycompany/myapp/config/DatabaseConfiguration.class]: Invocation of init method failed; nested exception is com.mongodb.MongoTimeoutException: Timed out after 30000 ms while waiting for a server that matches ReadPreferenceServerSelector{readPreference=primary}. Client view of cluster state is {type=UNKNOWN, servers=[{address=localhost:27017, type=UNKNOWN, state=CONNECTING, exception={com.mongodb.MongoSocketOpenException: Exception opening socket}, caused by {java.net.ConnectException: Connection refused: connect}}]
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1583)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:553)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:482)
at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:306)
at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:230)
at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:302)
at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:197)
at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:754)
at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:866)
at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:542)
at org.springframework.boot.context.embedded.EmbeddedWebApplicationContext.refresh(EmbeddedWebApplicationContext.java:122)
at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:761)
at org.springframework.boot.SpringApplication.refreshContext(SpringApplication.java:371)
at org.springframework.boot.SpringApplication.run(SpringApplication.java:315)
at com.mycompany.myapp.MdcApp.main(MdcApp.java:64)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at org.springframework.boot.devtools.restart.RestartLauncher.run(RestartLauncher.java:49)
Caused by: com.mongodb.MongoTimeoutException: Timed out after 30000 ms while waiting for a server that matches ReadPreferenceServerSelector{readPreference=primary}. Client view of cluster state is {type=UNKNOWN, servers=[{address=localhost:27017, type=UNKNOWN, state=CONNECTING, exception={com.mongodb.MongoSocketOpenException: Exception opening socket}, caused by {java.net.ConnectException: Connection refused: connect}}]
at com.mongodb.connection.BaseCluster.createTimeoutException(BaseCluster.java:369)
at com.mongodb.connection.BaseCluster.selectServer(BaseCluster.java:101)
at com.mongodb.binding.ClusterBinding$ClusterBindingConnectionSource.<init>(ClusterBinding.java:75)
at com.mongodb.binding.ClusterBinding$ClusterBindingConnectionSource.<init>(ClusterBinding.java:71)
at com.mongodb.binding.ClusterBinding.getReadConnectionSource(ClusterBinding.java:63)
at com.mongodb.operation.OperationHelper.withConnection(OperationHelper.java:210)
at com.mongodb.operation.FindOperation.execute(FindOperation.java:482)
at com.mongodb.operation.FindOperation.execute(FindOperation.java:79)
at com.mongodb.Mongo.execute(Mongo.java:772)
at com.mongodb.Mongo$2.execute(Mongo.java:759)
at com.mongodb.DBCollection.findOne(DBCollection.java:777)
at com.mongodb.DBCollection.findOne(DBCollection.java:747)
at com.mongodb.DBCollection.findOne(DBCollection.java:694)
at com.github.mongobee.dao.ChangeEntryIndexDao.findRequiredChangeAndAuthorIndex(ChangeEntryIndexDao.java:26)
at com.github.mongobee.dao.ChangeEntryDao.ensureChangeLogCollectionIndex(ChangeEntryDao.java:75)
at com.github.mongobee.dao.ChangeEntryDao.connectMongoDb(ChangeEntryDao.java:34)
at com.github.mongobee.Mongobee.execute(Mongobee.java:135)
at com.github.mongobee.Mongobee.afterPropertiesSet(Mongobee.java:117)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.invokeInitMethods(AbstractAutowireCapableBeanFactory.java:1642)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1579)
... 19 common frames omitted
I tried to create a similar project but without a Mongodb and it worked.
This error means that there was an error connecting to your database, it confirms this in your stacktrace:
Timed out after 30000 ms while waiting for a server
Please double check your database configuration in the application-dev.properties or application-dev.yml file under src/main/resources/config/.
Depending on whether you use YAML or JSON as the property definition file, double check the database configuration:
YAML:
spring:
data:
mongodb:
host: <your_host_address>
port: <your_port>
database: <database_name>
JSON:
spring.data.mongodb.host=<your_host_address>
spring.data.mongodb.port=<your_port>
spring.data.mongodb.database=<database_name>
After creating a new JHipster project with MongoDb I had the same error.
Before running mvnw (on Windows) I forgot to run the MongoDb itself.
So running mongod.exe in the new command prompt, and then running mvnw solved the issue for me.
This was able to solve my problem:
"Answered my own question...removing the #Bean definition from public
Mongobee mongobee(...) in DatabaseConfiguration.java seems to do the
trick. Haven't done any thorough testing, but the apps starts and I
can create new users."
Link: https://github.com/jhipster/generator-jhipster/issues/8665

Gracefull shutdown for Spring boot Application

I am running a spring-boot application and everything is good except when i try to close it. I got error on the below code
while (true) {
try {
if(level2List == null)
break;
CDR cdr = level2List.poll(2, TimeUnit.SECONDS);
The error is generated on the last line , spring boot is shutting down level2List before the 2 second wait is done as below
2015-05-29 17:32:15.758 INFO 27390 --- [ Thread-1] ationConfigEmbeddedWebApplicationContext : Closing org.springframework.boot.context.embedded.AnnotationConfigEmbeddedWebApplicationContext#358ee631: startup date [Fri May 29 17:31:17 GMT 2015]; root of context hierarchy
2015-05-29 17:32:15.765 INFO 27390 --- [ Thread-1] o.s.j.e.a.AnnotationMBeanExporter : Unregistering JMX-exposed beans on shutdown
2015-05-29 17:32:15.766 INFO 27390 --- [ Thread-1] o.s.j.e.a.AnnotationMBeanExporter : Unregistering JMX-exposed beans
2015-05-29 17:32:15.780 INFO 27390 --- [ Thread-1] o.s.c.ehcache.EhCacheManagerFactoryBean : Shutting down EhCache CacheManager
2015-05-29 17:32:15.804 INFO 27390 --- [ Thread-1] o.s.s.concurrent.ThreadPoolTaskExecutor : Shutting down ExecutorService 'level2ES'
2015-05-29 17:32:15.815 INFO 27390 --- [ Thread-1] o.s.s.concurrent.ThreadPoolTaskExecutor : Shutting down ExecutorService 'level1ES'
2015-05-29 17:32:15.823 INFO 27390 --- [ Thread-1] j.LocalContainerEntityManagerFactoryBean : Closing JPA EntityManagerFactory for persistence unit 'default'
2015-05-29 17:32:15.825 INFO 27390 --- [ Thread-1] com.jolbox.bonecp.BoneCP : Shutting down connection pool...
2015-05-29 17:32:15.833 INFO 27390 --- [ Thread-1] com.jolbox.bonecp.BoneCP : Connection pool has been shutdown.
2015-05-29 17:32:15.848 ERROR 27390 --- [pool-2-thread-1] c.t.t.c.process.CDRDataBase : Error
java.lang.InterruptedException: null
at java.util.concurrent.locks.AbstractQueuedSynchronizer$ConditionObject.reportInterruptAfterWait(AbstractQueuedSynchronizer.java:2014)
at java.util.concurrent.locks.AbstractQueuedSynchronizer$ConditionObject.awaitNanos(AbstractQueuedSynchronizer.java:2088)
at java.util.concurrent.LinkedBlockingQueue.poll(LinkedBlockingQueue.java:467)
at com.teltacworldwide.tekram.cdrserver.process.CDRDataBaseNative.run(CDRDataBaseNative.java:79)
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.scheduling.support.ScheduledMethodRunnable.run(ScheduledMethodRunnable.java:65)
at org.springframework.scheduling.support.DelegatingErrorHandlingRunnable.run(DelegatingErrorHandlingRunnable.java:54)
at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511)
at java.util.concurrent.FutureTask.runAndReset(FutureTask.java:308)
at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.access$301(ScheduledThreadPoolExecutor.java:180)
at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.run(ScheduledThreadPoolExecutor.java:294)
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)
Is there any way to order the shutting down process or to make sure I am not using level2List before shutting it down?
BR
Shahbour
I did two things
add
#Bean(destroyMethod = "shutdown")
public ThreadPoolTaskExecutor level1ES() {
also
} catch (InterruptedException e) {
log.warn("Closing application while CDR still in queue"); }
BR
Shahbour

Resources