在本文中,我们将带你了解在Spring-boot项目中更改版本时不会引发OptimisticLockException在这篇文章中,我们将为您详细介绍在Spring-boot项目中更改版本时不会引发O
在本文中,我们将带你了解在Spring-boot项目中更改版本时不会引发OptimisticLockException在这篇文章中,我们将为您详细介绍在Spring-boot项目中更改版本时不会引发OptimisticLockException的方方面面,并解答springboot版本修改常见的疑惑,同时我们还将给您一些技巧,以帮助您实现更有效的activiti6 乐观锁问题 org.activiti.engine.ActivitiOptimisticLockingException、Docker,Springboot和Mysql:com.mysql.cj.exceptions.CJCommunicationsException:通信链接失败、Error: java.io.IOException: org.apache.hadoop.hdfs.BlockMissingException: Could not obtain block、Exception in thread "main" joptsimple.UnrecognizedOptionException: zookeeper is not a reco。
本文目录一览:- 在Spring-boot项目中更改版本时不会引发OptimisticLockException(springboot版本修改)
- activiti6 乐观锁问题 org.activiti.engine.ActivitiOptimisticLockingException
- Docker,Springboot和Mysql:com.mysql.cj.exceptions.CJCommunicationsException:通信链接失败
- Error: java.io.IOException: org.apache.hadoop.hdfs.BlockMissingException: Could not obtain block
- Exception in thread "main" joptsimple.UnrecognizedOptionException: zookeeper is not a reco
在Spring-boot项目中更改版本时不会引发OptimisticLockException(springboot版本修改)
型号结构:
@MappedSuperclasspublic class BaseModel<K extends Comparable> implements Serializable, Comparable<Object> { private static final long serialVersionUID = 1L; @Id private K id; @Version private Integer version; // getter/setter}@Entitypublic class MyEntity extends BaseModel<String> { // some fields and it''s getter/setter}
在我的数据库中记录my_entity
:
id:1版本:1 …
下面是我的更新方法:
void update(String id, Integer currentVersion, ....) { MyEntity myEntity = myRepository.findOne(id); myEntity.setVersion(currentVersion); // other assignments myRepository.save(myEntity);}
下面是调用此方法时触发的查询。
update my_entity set version=?, x=?, y=?, ...where id=? and version=?
当currentVersion
在上述方法中传递的不是时,我期望OptimisticLockException 1
。
谁能帮我为什么我没有得到OptimisticLockException?我正在为我的webmvc项目使用spring-boot。
答案1
小编典典JPA规范的11.1.54节指出:
通常,应用程序不应更新使用Version批注指定的字段或属性。
根据经验,我可以建议您尝试手动更新版本字段时,某些JPA提供程序(OpenJPA是其中之一)实际上会引发异常。
虽然不是严格回答您的问题,但是您可以按以下方式进行重构,以确保JPA提供程序之间的可移植性以及对JPA规范的严格遵守:
public void update(String id, Integer currentVersion) throws MyWrappedException { MyEntity myEntity = myRepository.findOne(id); if(currentVersion != myEntity.getVersion()){ throw new MyWrappedException(); } myRepository.save(myEntity); //still an issue here however: see below}
假设您的update(...)
方法正在事务中运行,但是如JPA规范第3.4.5节所述,您仍然遇到上述问题:
3.4.5
OptimisticLockException与有效的锁定模式和刷新模式设置一致时,提供程序实现可以将对数据库的写操作推迟到事务结束。在这种情况下,直到提交时间才可能进行乐观锁检查,并且可能在提交的“完成之前”阶段引发OptimisticLockException。
如果OptimisticLockException必须由应用程序捕获或处理,则应用程序应使用flush方法来强制执行数据库写操作。
这将允许应用程序捕获和处理乐观锁异常。
基本上,两个用户可以同时提交同一实体的修改。这两个线程都可以通过初始检查,但是当更新被刷新到数据库时可能会失败,这可能是在事务提交时执行的,即在您的方法完成之后。
为了可以捕获和处理OptimisticLock异常,代码应如下所示:
public void update(String id, Integer currentVersion) throws MyWrappedException { MyEntity myEntity = myRepository.findOne(id); if(currentVersion != myEntity.getVersion()){ throw new MyWrappedException(); } myRepository.save(myEntity); try{ myRepository.flush() } catch(OptimisticLockingFailureException ex){ throw new MyWrappedException(); }}
activiti6 乐观锁问题 org.activiti.engine.ActivitiOptimisticLockingException
activiti6 乐观锁问题 org.activiti.engine.ActivitiOptimisticLockingException
- 使用identityService.saveUser()添加用户时出现以下问题:
org.activiti.engine.ActivitiOptimisticLockingException: org.activiti.engine.impl.persistence.entity.UserEntityImpl@10718783 was updated by another transaction concurrently
- 出现问题的代码
public void addUser(User user) {
// todo ...
identityService.saveUser(user);
}
- 解决方法
添加用户分两步操作:- 先调用identityService.newUser()传入userId得到user
- 再调用 identityService.saveUser(),向数据库中添加数据
- 解决问题之后的代码
public void addUser(User user, String systemId) {
User userEntity = identityService.newUser(user.getId()));
generalUser(userEntity, user);
identityService.saveUser(userEntity);
}
//处理数据
private void generalUser(User userEntity, User user){
userEntity.setFirstName(user.getFirstName());
userEntity.setLastName(user.getLastName());
userEntity.setEmail(user.getEmail());
userEntity.setPassword(user.getPassword());
}
- 添加其他数据时也可能出现这种情况,比如添加用户组数据,解决方法如上一致
Docker,Springboot和Mysql:com.mysql.cj.exceptions.CJCommunicationsException:通信链接失败
我尝试在Docker上使用mysql连接运行Springboot应用程序。没有码头工人,它运作良好。但是,当我尝试在容器上进行部署时,我有com.mysql.cj.exceptions.CJCommunicationsException:Communications link failure
。我使用这个docker-compose:
version: ''3''services: nginx: container_name: nginx image: nginx:latest restart: always ports: - 80:80 - 443:443 volumes: - ./nginx/conf.d:/etc/nginx/conf.d depends_on: - spring-boot-app mysql: container_name: mysql image: mysql:latest environment: MYSQL_ROOT_PASSWORD: "rootpass" MYSQL_DATABASE: "db" MYSQL_USER: "user" MYSQL_PASSWORD: "pass" ports: - "1306:3306" volumes: - ./data/:/var/lib/mysql networks: - mysql-db restart: always spring-boot-app: container_name: spring-boot-app image: spring-boot-app build: context: ./spring-boot-app dockerfile: Dockerfile ports: - "8080:8080" depends_on: - mysql networks: - mysql-db restart: alwaysnetworks: mysql-db: driver: bridge
这是springboot应用程序的Dockerfile:
FROM openjdk:11COPY target/spring-boot-app.jar /spring-boot-app/spring-boot-app.jarENTRYPOINT [ "java", "-jar", "-Dspring.profiles.active=prod","/spring-boot-app/spring-boot-app.jar" ]
最后,这是application.properties:
spring.datasource.url = jdbc:mysql://mysql:1306/dbspring.datasource.username = userspring.datasource.password = pass# Show or not log for each sql queryspring.jpa.show-sql = true# Hibernate ddl auto (create, create-drop, update)spring.jpa.hibernate.ddl-auto = update# Use spring.jpa.properties.* for Hibernate native properties (the prefix is# stripped before adding them to the entity manager)# The SQL dialect makes Hibernate generate better SQL for the chosen databasespring.jpa.properties.hibernate.dialect = org.hibernate.dialect.MySQL5Dialectserver.port=8080
我不认为这是端口问题,因为我尝试将mysql设置为默认端口(3306),但仍然无法正常工作。
如果可以帮助,这里是docker ps
:
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES08ea16361c61 nginx:latest "nginx -g ''daemon of…" 1 second ago Up Less than a second 0.0.0.0:80->80/tcp, 0.0.0.0:443->443/tcp nginx52ef8d5c2127 spring-boot-app "java -jar -Dspring.…" 3 seconds ago Up 1 second 0.0.0.0:8080->8080/tcp spring-boot-app7bbcdc1fae3c mysql:latest "docker-entrypoint.s…" 4 seconds ago Up 3 seconds 33060/tcp, 0.0.0.0:1306->3306/tcp mysql
编辑:完整的堆栈跟踪:
ubuntu@ubuntu:~/Documents/SpringBoot$ docker-compose upCreating network "springboot_mysql-db" with driver "bridge"Creating mysql ... doneCreating spring-boot-app ... doneAttaching to mysql, spring-boot-appmysql | 2019-05-27T21:50:19.645920Z 0 [Warning] [MY-011070] [Server] ''Disabling symbolic links using --skip-symbolic-links (or equivalent) is the default. Consider not using this option as it'' is deprecated and will be removed in a future release.mysql | 2019-05-27T21:50:19.645986Z 0 [System] [MY-010116] [Server] /usr/sbin/mysqld (mysqld 8.0.16) starting as process 1mysql | 2019-05-27T21:50:20.451523Z 0 [System] [MY-010229] [Server] Starting crash recovery...mysql | 2019-05-27T21:50:20.466040Z 0 [System] [MY-010232] [Server] Crash recovery finished.mysql | 2019-05-27T21:50:20.544487Z 0 [Warning] [MY-010068] [Server] CA certificate ca.pem is self signed.mysql | 2019-05-27T21:50:20.551894Z 0 [Warning] [MY-011810] [Server] Insecure configuration for --pid-file: Location ''/var/run/mysqld'' in the path is accessible to all OS users. Consider choosing a different directory.mysql | 2019-05-27T21:50:20.584210Z 0 [System] [MY-010931] [Server] /usr/sbin/mysqld: ready for connections. Version: ''8.0.16'' socket: ''/var/run/mysqld/mysqld.sock'' port: 3306 MySQL Community Server - GPL.mysql | 2019-05-27T21:50:20.682338Z 0 [System] [MY-011323] [Server] X Plugin ready for connections. Socket: ''/var/run/mysqld/mysqlx.sock'' bind-address: ''::'' port: 33060spring-boot-app | spring-boot-app | . ____ _ __ _ _spring-boot-app | /\\ / ___''_ __ _ _(_)_ __ __ _ \ \ \ \spring-boot-app | ( ( )\___ | ''_ | ''_| | ''_ \/ _` | \ \ \ \spring-boot-app | \\/ ___)| |_)| | | | | || (_| | ) ) ) )spring-boot-app | '' |____| .__|_| |_|_| |_\__, | / / / /spring-boot-app | =========|_|==============|___/=/_/_/_/spring-boot-app | :: Spring Boot :: (v2.1.5.RELEASE)spring-boot-app | spring-boot-app | 2019-05-27 21:50:22.884 INFO 1 --- [ main] com.jv.demo.DemoApplication : Starting DemoApplication v0.0.1-SNAPSHOT on c69469fd7461 with PID 1 (/spring-boot-app/spring-boot-app.jar started by root in /)spring-boot-app | 2019-05-27 21:50:22.903 INFO 1 --- [ main] com.jv.demo.DemoApplication : The following profiles are active: prodspring-boot-app | 2019-05-27 21:50:25.152 INFO 1 --- [ main] .s.d.r.c.RepositoryConfigurationDelegate : Bootstrapping Spring Data repositories in DEFAULT mode.spring-boot-app | 2019-05-27 21:50:25.378 INFO 1 --- [ main] .s.d.r.c.RepositoryConfigurationDelegate : Finished Spring Data repository scanning in 205ms. Found 1 repository interfaces.spring-boot-app | 2019-05-27 21:50:26.313 INFO 1 --- [ main] trationDelegate$BeanPostProcessorChecker : Bean ''org.springframework.transaction.annotation.ProxyTransactionManagementConfiguration'' of type [org.springframework.transaction.annotation.ProxyTransactionManagementConfiguration$$EnhancerBySpringCGLIB$$e43b97d] is not eligible for getting processed by all BeanPostProcessors (for example: not eligible for auto-proxying)spring-boot-app | 2019-05-27 21:50:27.043 INFO 1 --- [ main] o.s.b.w.embedded.tomcat.TomcatWebServer : Tomcat initialized with port(s): 8080 (http)spring-boot-app | 2019-05-27 21:50:27.195 INFO 1 --- [ main] o.apache.catalina.core.StandardService : Starting service [Tomcat]spring-boot-app | 2019-05-27 21:50:27.196 INFO 1 --- [ main] org.apache.catalina.core.StandardEngine : Starting Servlet engine: [Apache Tomcat/9.0.19]spring-boot-app | 2019-05-27 21:50:27.472 INFO 1 --- [ main] o.a.c.c.C.[Tomcat].[localhost].[/] : Initializing Spring embedded WebApplicationContextspring-boot-app | 2019-05-27 21:50:27.472 INFO 1 --- [ main] o.s.web.context.ContextLoader : Root WebApplicationContext: initialization completed in 4316 msspring-boot-app | 2019-05-27 21:50:27.928 INFO 1 --- [ main] com.zaxxer.hikari.HikariDataSource : HikariPool-1 - Starting...spring-boot-app | 2019-05-27 21:50:29.226 ERROR 1 --- [ main] com.zaxxer.hikari.pool.HikariPool : HikariPool-1 - Exception during pool initialization.spring-boot-app | spring-boot-app | com.mysql.cj.jdbc.exceptions.CommunicationsException: Communications link failurespring-boot-app | spring-boot-app | The last packet sent successfully to the server was 0 milliseconds ago. The driver has not received any packets from the server.spring-boot-app | at com.mysql.cj.jdbc.exceptions.SQLError.createCommunicationsException(SQLError.java:174) ~[mysql-connector-java-8.0.16.jar!/:8.0.16]spring-boot-app | at com.mysql.cj.jdbc.exceptions.SQLExceptionsMapping.translateException(SQLExceptionsMapping.java:64) ~[mysql-connector-java-8.0.16.jar!/:8.0.16]spring-boot-app | at com.mysql.cj.jdbc.ConnectionImpl.createNewIO(ConnectionImpl.java:835) ~[mysql-connector-java-8.0.16.jar!/:8.0.16]spring-boot-app | at com.mysql.cj.jdbc.ConnectionImpl.<init>(ConnectionImpl.java:455) ~[mysql-connector-java-8.0.16.jar!/:8.0.16]spring-boot-app | at com.mysql.cj.jdbc.ConnectionImpl.getInstance(ConnectionImpl.java:240) ~[mysql-connector-java-8.0.16.jar!/:8.0.16]spring-boot-app | at com.mysql.cj.jdbc.NonRegisteringDriver.connect(NonRegisteringDriver.java:199) ~[mysql-connector-java-8.0.16.jar!/:8.0.16]spring-boot-app | at com.zaxxer.hikari.util.DriverDataSource.getConnection(DriverDataSource.java:136) ~[HikariCP-3.2.0.jar!/:na]spring-boot-app | at com.zaxxer.hikari.pool.PoolBase.newConnection(PoolBase.java:369) ~[HikariCP-3.2.0.jar!/:na]spring-boot-app | at com.zaxxer.hikari.pool.PoolBase.newPoolEntry(PoolBase.java:198) ~[HikariCP-3.2.0.jar!/:na]spring-boot-app | at com.zaxxer.hikari.pool.HikariPool.createPoolEntry(HikariPool.java:467) ~[HikariCP-3.2.0.jar!/:na]spring-boot-app | at com.zaxxer.hikari.pool.HikariPool.checkFailFast(HikariPool.java:541) ~[HikariCP-3.2.0.jar!/:na]spring-boot-app | at com.zaxxer.hikari.pool.HikariPool.<init>(HikariPool.java:115) ~[HikariCP-3.2.0.jar!/:na]spring-boot-app | at com.zaxxer.hikari.HikariDataSource.getConnection(HikariDataSource.java:112) ~[HikariCP-3.2.0.jar!/:na]spring-boot-app | at org.springframework.jdbc.datasource.DataSourceUtils.fetchConnection(DataSourceUtils.java:157) ~[spring-jdbc-5.1.7.RELEASE.jar!/:5.1.7.RELEASE]spring-boot-app | at org.springframework.jdbc.datasource.DataSourceUtils.doGetConnection(DataSourceUtils.java:115) ~[spring-jdbc-5.1.7.RELEASE.jar!/:5.1.7.RELEASE]spring-boot-app | at org.springframework.jdbc.datasource.DataSourceUtils.getConnection(DataSourceUtils.java:78) ~[spring-jdbc-5.1.7.RELEASE.jar!/:5.1.7.RELEASE]spring-boot-app | at org.springframework.jdbc.support.JdbcUtils.extractDatabaseMetaData(JdbcUtils.java:319) ~[spring-jdbc-5.1.7.RELEASE.jar!/:5.1.7.RELEASE]spring-boot-app | at org.springframework.jdbc.support.JdbcUtils.extractDatabaseMetaData(JdbcUtils.java:356) ~[spring-jdbc-5.1.7.RELEASE.jar!/:5.1.7.RELEASE]spring-boot-app | at org.springframework.boot.autoconfigure.orm.jpa.DatabaseLookup.getDatabase(DatabaseLookup.java:73) ~[spring-boot-autoconfigure-2.1.5.RELEASE.jar!/:2.1.5.RELEASE]spring-boot-app | at org.springframework.boot.autoconfigure.orm.jpa.JpaProperties.determineDatabase(JpaProperties.java:142) ~[spring-boot-autoconfigure-2.1.5.RELEASE.jar!/:2.1.5.RELEASE]spring-boot-app | at org.springframework.boot.autoconfigure.orm.jpa.JpaBaseConfiguration.jpaVendorAdapter(JpaBaseConfiguration.java:113) ~[spring-boot-autoconfigure-2.1.5.RELEASE.jar!/:2.1.5.RELEASE]spring-boot-app | at org.springframework.boot.autoconfigure.orm.jpa.HibernateJpaConfiguration$$EnhancerBySpringCGLIB$$2d1a7bec.CGLIB$jpaVendorAdapter$5(<generated>) ~[spring-boot-autoconfigure-2.1.5.RELEASE.jar!/:2.1.5.RELEASE]spring-boot-app | at org.springframework.boot.autoconfigure.orm.jpa.HibernateJpaConfiguration$$EnhancerBySpringCGLIB$$2d1a7bec$$FastClassBySpringCGLIB$$cb57d9da.invoke(<generated>) ~[spring-boot-autoconfigure-2.1.5.RELEASE.jar!/:2.1.5.RELEASE]spring-boot-app | at org.springframework.cglib.proxy.MethodProxy.invokeSuper(MethodProxy.java:244) ~[spring-core-5.1.7.RELEASE.jar!/:5.1.7.RELEASE]spring-boot-app | at org.springframework.context.annotation.ConfigurationClassEnhancer$BeanMethodInterceptor.intercept(ConfigurationClassEnhancer.java:363) ~[spring-context-5.1.7.RELEASE.jar!/:5.1.7.RELEASE]spring-boot-app | at org.springframework.boot.autoconfigure.orm.jpa.HibernateJpaConfiguration$$EnhancerBySpringCGLIB$$2d1a7bec.jpaVendorAdapter(<generated>) ~[spring-boot-autoconfigure-2.1.5.RELEASE.jar!/:2.1.5.RELEASE]spring-boot-app | at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[na:na]spring-boot-app | at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) ~[na:na]spring-boot-app | at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[na:na]spring-boot-app | at java.base/java.lang.reflect.Method.invoke(Method.java:566) ~[na:na]spring-boot-app | at org.springframework.beans.factory.support.SimpleInstantiationStrategy.instantiate(SimpleInstantiationStrategy.java:154) ~[spring-beans-5.1.7.RELEASE.jar!/:5.1.7.RELEASE]spring-boot-app | at org.springframework.beans.factory.support.ConstructorResolver.instantiate(ConstructorResolver.java:622) ~[spring-beans-5.1.7.RELEASE.jar!/:5.1.7.RELEASE]spring-boot-app | at org.springframework.beans.factory.support.ConstructorResolver.instantiateUsingFactoryMethod(ConstructorResolver.java:456) ~[spring-beans-5.1.7.RELEASE.jar!/:5.1.7.RELEASE]spring-boot-app | at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.instantiateUsingFactoryMethod(AbstractAutowireCapableBeanFactory.java:1321) ~[spring-beans-5.1.7.RELEASE.jar!/:5.1.7.RELEASE]spring-boot-app | at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBeanInstance(AbstractAutowireCapableBeanFactory.java:1160) ~[spring-beans-5.1.7.RELEASE.jar!/:5.1.7.RELEASE]spring-boot-app | at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:555) ~[spring-beans-5.1.7.RELEASE.jar!/:5.1.7.RELEASE]spring-boot-app | at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:515) ~[spring-beans-5.1.7.RELEASE.jar!/:5.1.7.RELEASE]spring-boot-app | at org.springframework.beans.factory.support.AbstractBeanFactory.lambda$doGetBean$0(AbstractBeanFactory.java:320) ~[spring-beans-5.1.7.RELEASE.jar!/:5.1.7.RELEASE]spring-boot-app | at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:222) ~[spring-beans-5.1.7.RELEASE.jar!/:5.1.7.RELEASE]spring-boot-app | at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:318) ~[spring-beans-5.1.7.RELEASE.jar!/:5.1.7.RELEASE]spring-boot-app | at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:199) ~[spring-beans-5.1.7.RELEASE.jar!/:5.1.7.RELEASE]spring-boot-app | at org.springframework.beans.factory.config.DependencyDescriptor.resolveCandidate(DependencyDescriptor.java:277) ~[spring-beans-5.1.7.RELEASE.jar!/:5.1.7.RELEASE]spring-boot-app | at org.springframework.beans.factory.support.DefaultListableBeanFactory.doResolveDependency(DefaultListableBeanFactory.java:1248) ~[spring-beans-5.1.7.RELEASE.jar!/:5.1.7.RELEASE]spring-boot-app | at org.springframework.beans.factory.support.DefaultListableBeanFactory.resolveDependency(DefaultListableBeanFactory.java:1168) ~[spring-beans-5.1.7.RELEASE.jar!/:5.1.7.RELEASE]spring-boot-app | at org.springframework.beans.factory.support.ConstructorResolver.resolveAutowiredArgument(ConstructorResolver.java:857) ~[spring-beans-5.1.7.RELEASE.jar!/:5.1.7.RELEASE]spring-boot-app | at org.springframework.beans.factory.support.ConstructorResolver.createArgumentArray(ConstructorResolver.java:760) ~[spring-beans-5.1.7.RELEASE.jar!/:5.1.7.RELEASE]spring-boot-app | at org.springframework.beans.factory.support.ConstructorResolver.instantiateUsingFactoryMethod(ConstructorResolver.java:509) ~[spring-beans-5.1.7.RELEASE.jar!/:5.1.7.RELEASE]spring-boot-app | at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.instantiateUsingFactoryMethod(AbstractAutowireCapableBeanFactory.java:1321) ~[spring-beans-5.1.7.RELEASE.jar!/:5.1.7.RELEASE]spring-boot-app | at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBeanInstance(AbstractAutowireCapableBeanFactory.java:1160) ~[spring-beans-5.1.7.RELEASE.jar!/:5.1.7.RELEASE]spring-boot-app | at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:555) ~[spring-beans-5.1.7.RELEASE.jar!/:5.1.7.RELEASE]spring-boot-app | at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:515) ~[spring-beans-5.1.7.RELEASE.jar!/:5.1.7.RELEASE]spring-boot-app | at org.springframework.beans.factory.support.AbstractBeanFactory.lambda$doGetBean$0(AbstractBeanFactory.java:320) ~[spring-beans-5.1.7.RELEASE.jar!/:5.1.7.RELEASE]spring-boot-app | at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:222) ~[spring-beans-5.1.7.RELEASE.jar!/:5.1.7.RELEASE]spring-boot-app | at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:318) ~[spring-beans-5.1.7.RELEASE.jar!/:5.1.7.RELEASE]spring-boot-app | at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:199) ~[spring-beans-5.1.7.RELEASE.jar!/:5.1.7.RELEASE]spring-boot-app | at org.springframework.beans.factory.config.DependencyDescriptor.resolveCandidate(DependencyDescriptor.java:277) ~[spring-beans-5.1.7.RELEASE.jar!/:5.1.7.RELEASE]spring-boot-app | at org.springframework.beans.factory.support.DefaultListableBeanFactory.doResolveDependency(DefaultListableBeanFactory.java:1248) ~[spring-beans-5.1.7.RELEASE.jar!/:5.1.7.RELEASE]spring-boot-app | at org.springframework.beans.factory.support.DefaultListableBeanFactory.resolveDependency(DefaultListableBeanFactory.java:1168) ~[spring-beans-5.1.7.RELEASE.jar!/:5.1.7.RELEASE]spring-boot-app | at org.springframework.beans.factory.support.ConstructorResolver.resolveAutowiredArgument(ConstructorResolver.java:857) ~[spring-beans-5.1.7.RELEASE.jar!/:5.1.7.RELEASE]spring-boot-app | at org.springframework.beans.factory.support.ConstructorResolver.createArgumentArray(ConstructorResolver.java:760) ~[spring-beans-5.1.7.RELEASE.jar!/:5.1.7.RELEASE]spring-boot-app | at org.springframework.beans.factory.support.ConstructorResolver.instantiateUsingFactoryMethod(ConstructorResolver.java:509) ~[spring-beans-5.1.7.RELEASE.jar!/:5.1.7.RELEASE]spring-boot-app | at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.instantiateUsingFactoryMethod(AbstractAutowireCapableBeanFactory.java:1321) ~[spring-beans-5.1.7.RELEASE.jar!/:5.1.7.RELEASE]spring-boot-app | at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBeanInstance(AbstractAutowireCapableBeanFactory.java:1160) ~[spring-beans-5.1.7.RELEASE.jar!/:5.1.7.RELEASE]spring-boot-app | at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:555) ~[spring-beans-5.1.7.RELEASE.jar!/:5.1.7.RELEASE]spring-boot-app | at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:515) ~[spring-beans-5.1.7.RELEASE.jar!/:5.1.7.RELEASE]spring-boot-app | at org.springframework.beans.factory.support.AbstractBeanFactory.lambda$doGetBean$0(AbstractBeanFactory.java:320) ~[spring-beans-5.1.7.RELEASE.jar!/:5.1.7.RELEASE]spring-boot-app | at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:222) ~[spring-beans-5.1.7.RELEASE.jar!/:5.1.7.RELEASE]spring-boot-app | at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:318) ~[spring-beans-5.1.7.RELEASE.jar!/:5.1.7.RELEASE]spring-boot-app | at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:199) ~[spring-beans-5.1.7.RELEASE.jar!/:5.1.7.RELEASE]spring-boot-app | at org.springframework.context.support.AbstractApplicationContext.getBean(AbstractApplicationContext.java:1105) ~[spring-context-5.1.7.RELEASE.jar!/:5.1.7.RELEASE]spring-boot-app | at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:867) ~[spring-context-5.1.7.RELEASE.jar!/:5.1.7.RELEASE]spring-boot-app | at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:549) ~[spring-context-5.1.7.RELEASE.jar!/:5.1.7.RELEASE]spring-boot-app | at org.springframework.boot.web.servlet.context.ServletWebServerApplicationContext.refresh(ServletWebServerApplicationContext.java:142) ~[spring-boot-2.1.5.RELEASE.jar!/:2.1.5.RELEASE]spring-boot-app | at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:775) ~[spring-boot-2.1.5.RELEASE.jar!/:2.1.5.RELEASE]spring-boot-app | at org.springframework.boot.SpringApplication.refreshContext(SpringApplication.java:397) ~[spring-boot-2.1.5.RELEASE.jar!/:2.1.5.RELEASE]spring-boot-app | at org.springframework.boot.SpringApplication.run(SpringApplication.java:316) ~[spring-boot-2.1.5.RELEASE.jar!/:2.1.5.RELEASE]spring-boot-app | at org.springframework.boot.SpringApplication.run(SpringApplication.java:1260) ~[spring-boot-2.1.5.RELEASE.jar!/:2.1.5.RELEASE]spring-boot-app | at org.springframework.boot.SpringApplication.run(SpringApplication.java:1248) ~[spring-boot-2.1.5.RELEASE.jar!/:2.1.5.RELEASE]spring-boot-app | at com.jv.demo.DemoApplication.main(DemoApplication.java:10) ~[classes!/:0.0.1-SNAPSHOT]spring-boot-app | at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[na:na]spring-boot-app | at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) ~[na:na]spring-boot-app | at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[na:na]spring-boot-app | at java.base/java.lang.reflect.Method.invoke(Method.java:566) ~[na:na]spring-boot-app | at org.springframework.boot.loader.MainMethodRunner.run(MainMethodRunner.java:48) ~[spring-boot-app.jar:0.0.1-SNAPSHOT]spring-boot-app | at org.springframework.boot.loader.Launcher.launch(Launcher.java:87) ~[spring-boot-app.jar:0.0.1-SNAPSHOT]spring-boot-app | at org.springframework.boot.loader.Launcher.launch(Launcher.java:50) ~[spring-boot-app.jar:0.0.1-SNAPSHOT]spring-boot-app | at org.springframework.boot.loader.JarLauncher.main(JarLauncher.java:51) ~[spring-boot-app.jar:0.0.1-SNAPSHOT]spring-boot-app | Caused by: com.mysql.cj.exceptions.CJCommunicationsException: Communications link failurespring-boot-app | spring-boot-app | The last packet sent successfully to the server was 0 milliseconds ago. The driver has not received any packets from the server.spring-boot-app | at java.base/jdk.internal.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method) ~[na:na]spring-boot-app | at java.base/jdk.internal.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62) ~[na:na]spring-boot-app | at java.base/jdk.internal.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45) ~[na:na]spring-boot-app | at java.base/java.lang.reflect.Constructor.newInstance(Constructor.java:490) ~[na:na]spring-boot-app | at com.mysql.cj.exceptions.ExceptionFactory.createException(ExceptionFactory.java:61) ~[mysql-connector-java-8.0.16.jar!/:8.0.16]spring-boot-app | at com.mysql.cj.exceptions.ExceptionFactory.createException(ExceptionFactory.java:105) ~[mysql-connector-java-8.0.16.jar!/:8.0.16]spring-boot-app | at com.mysql.cj.exceptions.ExceptionFactory.createException(ExceptionFactory.java:151) ~[mysql-connector-java-8.0.16.jar!/:8.0.16]spring-boot-app | at com.mysql.cj.exceptions.ExceptionFactory.createCommunicationsException(ExceptionFactory.java:167) ~[mysql-connector-java-8.0.16.jar!/:8.0.16]spring-boot-app | at com.mysql.cj.protocol.a.NativeSocketConnection.connect(NativeSocketConnection.java:91) ~[mysql-connector-java-8.0.16.jar!/:8.0.16]spring-boot-app | at com.mysql.cj.NativeSession.connect(NativeSession.java:152) ~[mysql-connector-java-8.0.16.jar!/:8.0.16]spring-boot-app | at com.mysql.cj.jdbc.ConnectionImpl.connectOneTryOnly(ConnectionImpl.java:955) ~[mysql-connector-java-8.0.16.jar!/:8.0.16]spring-boot-app | at com.mysql.cj.jdbc.ConnectionImpl.createNewIO(ConnectionImpl.java:825) ~[mysql-connector-java-8.0.16.jar!/:8.0.16]spring-boot-app | ... 84 common frames omittedspring-boot-app | Caused by: java.net.ConnectException: Connection refused (Connection refused)spring-boot-app | at java.base/java.net.PlainSocketImpl.socketConnect(Native Method) ~[na:na]spring-boot-app | at java.base/java.net.AbstractPlainSocketImpl.doConnect(AbstractPlainSocketImpl.java:399) ~[na:na]spring-boot-app | at java.base/java.net.AbstractPlainSocketImpl.connectToAddress(AbstractPlainSocketImpl.java:242) ~[na:na]spring-boot-app | at java.base/java.net.AbstractPlainSocketImpl.connect(AbstractPlainSocketImpl.java:224) ~[na:na]spring-boot-app | at java.base/java.net.SocksSocketImpl.connect(SocksSocketImpl.java:403) ~[na:na]spring-boot-app | at java.base/java.net.Socket.connect(Socket.java:591) ~[na:na]spring-boot-app | at com.mysql.cj.protocol.StandardSocketFactory.connect(StandardSocketFactory.java:155) ~[mysql-connector-java-8.0.16.jar!/:8.0.16]spring-boot-app | at com.mysql.cj.protocol.a.NativeSocketConnection.connect(NativeSocketConnection.java:65) ~[mysql-connector-java-8.0.16.jar!/:8.0.16]spring-boot-app | ... 87 common frames omittedspring-boot-app | spring-boot-app | 2019-05-27 21:50:29.234 WARN 1 --- [ main] o.s.b.a.orm.jpa.DatabaseLookup : Unable to determine jdbc url from datasourcespring-boot-app | spring-boot-app | org.springframework.jdbc.support.MetaDataAccessException: Could not get Connection for extracting meta-data; nested exception is org.springframework.jdbc.CannotGetJdbcConnectionException: Failed to obtain JDBC Connection; nested exception is com.mysql.cj.jdbc.exceptions.CommunicationsException: Communications link failure
答案1
小编典典由于您的Spring Boot应用程序也在docker映像中启动,因此您无法使用docker公开的端口,而需要使用映像的原始端口。
在application.properties
您需要使用:
spring.datasource.url = jdbc:mysql://mysql:3306/db
Error: java.io.IOException: org.apache.hadoop.hdfs.BlockMissingException: Could not obtain block
在Hive命令行执行查询时,出现错误
Error: java.io.IOException: org.apache.hadoop.hdfs.BlockMissingException: Could not obtain block: BP-787476470-192.168.152.10-1573351961380:blk_1073742171_1347 file=/user/hive/warehouse/db_hive.db/emp/emp.txt (state=,code=0)
根据信息得知是无法找到数据块,登陆webUI监控界面,master:50070,发现只有一个DataNode slave2, slave1没有启动。
cd到slave1的sbin/目录下,手动启动DataNode,刷新监控界面,slave1的datanode已经启动了,Hive查询也不再报错。
[root@slave1 sbin]# ./hadoop-daemon.sh start datanode
在HDFS中,提供了fsck命令,用于检查HDFS上文件和目录的健康状态、获取文件的block信息和位置信息等。
fsck命令必须由HDFS超级用户来执行,普通用户无权限。
查看文件中损坏的块(-list-corruptfileblocks)
[root@master sbin]$ hdfs fsck / -list-corruptfileblocks
将损坏的文件移动至/lost+found目录(-move)
[root@master sbin]$ hdfs fsck / -move
删除损坏的文件(-delete)
[root@master sbin]$ hdfs fsck / -delete
检查并列出所有文件状态(-files)
[root@master sbin]$ hdfs fsck / -files
查看dfs块的报告
[root@master sbin]$ hdfs dfsadmin -report
Exception in thread "main" joptsimple.UnrecognizedOptionException: zookeeper is not a reco
在创建主题时,
在较新版本(2.2 及更高版本)的 Kafka 不再需要 ZooKeeper 连接字符串,即- -zookeeper localhost:2181。使用 Kafka broker的 --bootstrap-server localhost:9092来替代- -zookeeper localhost:2181。
即使用命令:
bin/kafka-topics.sh --create --bootstrap-server localhost:9092 --replication-factor 1 --partitions 1 --topic test
替代命令:
bin/kafka-topics.sh --create --zookeeper localhost:2181 --replication-factor 1 --partitions 1 --topic test
关于在Spring-boot项目中更改版本时不会引发OptimisticLockException和springboot版本修改的问题我们已经讲解完毕,感谢您的阅读,如果还想了解更多关于activiti6 乐观锁问题 org.activiti.engine.ActivitiOptimisticLockingException、Docker,Springboot和Mysql:com.mysql.cj.exceptions.CJCommunicationsException:通信链接失败、Error: java.io.IOException: org.apache.hadoop.hdfs.BlockMissingException: Could not obtain block、Exception in thread "main" joptsimple.UnrecognizedOptionException: zookeeper is not a reco等相关内容,可以在本站寻找。
本文标签: