Skip to main content

40 posts tagged with "troubleshooting"

View All Tags

spring-boot项目中yml配置文件对duration配置在不给定单位的情况下默认为毫秒

· One min read
orange
programmer on jvm platform

如果在application.yml中配置duration值时不给定单位的话, 那么解析出的单位为毫秒, 如果需要自定义单位的话需要提供@DurationUnit,

建议配置Duration单位, 强制指定单位确保行为符合期望

内部调用栈

  • BindConverter
  • List<ConversionService> delegates
  • List<Converter> converters
  • StringToDurationConverter (SpringBoot)
  • NumberToDurationConverter (SpringBoot) 此处会根据注解去判断单位
  • DurationStyle.SIMPLE.parse

在gradle项目中使用platform导入其他gradle公共库项目时报错

· 2 min read
orange
programmer on jvm platform

在别的项目中使用platform导入内部公共库时报错, 报错信息如下:

FAILURE: Build failed with an exception.

* What went wrong:
Execution failed for task ':extractIncludeProto'.
> Could not resolve all files for configuration ':compileProtoPath'.
> Could not resolve com.fastonetech.library:fastone-bom:1.1.0-SNAPSHOT.
Required by:
project :
> No matching variant of com.fastonetech.library:fastone-bom:0.1.0-SNAPSHOT:20221123.055858-93 was found. The consumer was configured to find a runtime of a platform, preferably only the resources files but:
- Variant 'apiElements' capability com.fastonetech.library:fastone-bom:0.1.0-SNAPSHOT declares a component, packaged as a jar:
- Incompatible because this component declares an API of a library and the consumer needed a runtime of a platform
- Variant 'runtimeElements' capability com.fastonetech.library:fastone-bom:0.1.0-SNAPSHOT declares a runtime of a component, packaged as a jar:
- Incompatible because this component declares a library and the consumer needed a platform
> Could not find com.fastonetech.library:filter-spring-boot-starter:.
Required by:
project :
> Could not find com.fastonetech.library:rpc-spring-boot-starter:.
Required by:
project :
> Could not find com.fastonetech.library:security-spring-boot-starter:.
Required by:
project :
> Could not find com.fastonetech.library:prometheus-querying-client:.
Required by:
project :

JavaDelegate里调用Service的方法并且Service方法上有@Transactional注解但DB修改未生效

· 2 min read
orange
programmer on jvm platform

原因

Camunda调用Delegate时会开启事务(为了保证失败时可以回滚数据), Spring的@Transaction propagation = Propagation.REQUIRED , 然后就用了Camunda的那个事务, Camunda的事务中修改是对DB不生效的所以你看不到事务过程中修改的数据提交的结果

解决方案


@Component
class StartClusterDelegate(
private val clusterOperator: ClusterOperator
) : JavaDelegate, LogCapability {

override fun execute(execution: DelegateExecution) {
clusterOperator.start(execution.getVariableAs(VARNAME_CLUSTER_ID))
}
}

@Component
class ClusterOperator(
private val clusterService: ClusterService,
private val csClusterOperator: CsClusterOperator,
private val csStorageOperator: CsStorageOperator,
private val clusterBastionUserOperator: ClusterBastionUserOperator,
private val netEnvOperator: NetEnvOperator
) : LongTimeOperationCapability {

override fun start(id: Long) {
clusterService.get(id).orNull()!!.let { cluster ->
clusterService.patch(id) {
state = ClusterState.STARTING
}
logger.info("Begin start cluster $id")
csStorageOperator.start(cluster.csStorageId)
csClusterOperator.start(cluster.csClusterId!!)
clusterBastionUserOperator.start(cluster.id)
logger.info("Successful to start cluster $id")
clusterService.patch(id) {
state = ClusterState.RUNNING
}
}

}

}

@Service
class ClusterService(
private val engine: ProcessEngine,
private val clusterRepo: ClusterRepository,
private val client: DeployService
) : LogCapability {

@Transactional(propagation = Propagation.REQUIRES_NEW)
fun patch(id: Long, patchFun: PatchClusterDto.() -> Unit): Either<ClusterOperationError, ClusterDetail> =
clusterRepo.findById(id).map { originCluster ->
val patch = PatchClusterDto(patchFun).apply {
logger.info("patch request {}", this)
}
val patchedCluster = originCluster.copy(
cloudAccount = patch.cloudAccount ?: originCluster.cloudAccount,
csNetEnvId = patch.csNetEnvId ?: originCluster.csNetEnvId,
csStorageId = patch.csStoreId ?: originCluster.csStorageId,
csClusterId = patch.csClusterId ?: originCluster.csClusterId,
isDelivered = when (patch.deliveryCluster) {
DeliveryCluster.YES -> true
DeliveryCluster.NO -> false
DeliveryCluster.NONE -> originCluster.isDelivered
},
state = patch.state ?: originCluster.state
)
patchedCluster.apply {
logger.info("patched cluster {}", this)
}
}.map {
clusterRepo.save(it)
get(it.id)
}.orElseGet {
Either.left(ClusterOperationError.NoSuchCluster(id))
}
}

在kotlin项目中kotlin-jpa插件导致导致null检查失效

· One min read
orange
programmer on jvm platform

kotlin-jpa插件会为data class生成无参构造器,导致非空字段跳过了Null检查

@Entity
class ProjectInfo(
var name: String,
var code: String,
var ownerName: String,
var applicantName: String,
var companyCode: String,
var companyName: String,
var projectType: ProjectType,
var submitDate: LocalDateTime = LocalDateTime.now(),
var planStartDate: LocalDate?,
var planEndDate: LocalDate?,
var endDate: String,
var targetCustomers: Array<String>?,
var formStatus: ApplicationStatus = ApplicationStatus.DRAFT,
var projectStatus: ApplicationProjectStatus = ApplicationProjectStatus.DRAFT,
var comments: String?
) {

@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
val id: Long = -1
}

maven下载依赖时出现报错Could not transfer artifact xxx from/to maven-default-http-blocker (http://0.0.0.0/)

· One min read
orange
programmer on jvm platform

maven下载依赖时出现报错

[ERROR] Failed to execute goal on project specification-lib: Could not resolve dependencies for project com.fastonetech:specification-lib:jar:3.0.0-SNAPSHOT: Failed to collect dependencies at io.cucumber:cucumber-spring:jar:7.9.0 -> io.cucumber:cucumber-core:jar:7.9.0 -> io.cucumber:html-formatter:jar:20.1.0 -> io.cucumber:messages:jar:19.1.4-SNAPSHOT: Failed to read artifact descriptor for io.cucumber:messages:jar:19.1.4-SNAPSHOT: Could not transfer artifact io.cucumber:messages:pom:19.1.4-SNAPSHOT from/to maven-default-http-blocker (http://0.0.0.0/): Blocked mirror for repositories: [nexus-tencentyun (http://mirrors.tencent.com/nexus/repository/maven-public/, default, releases+snapshots), fastone (http://nexus.fastonetech.com/repository/fastone-snapshot/, default, releases+snapshots)] -> [Help 1]