Skip to main content

19 posts tagged with "java"

View All Tags

protobuf生成的java代码编译报错找不到symbol

· 3 min read
orange
programmer on jvm platform

使用gradle build时报错找不到symbol, 输出如下

> Task :compileJava FAILED
/home/orange/Documents/Dev/Project/Fastone/mgmt-api/build/generated/main/java/nott/v1/events/quota/Mgmt2StackQuota.java:430: error: cannot find symbol
if (!super.parseUnknownField(input, extensionRegistry, tag)) {
^
symbol: method parseUnknownField(CodedInputStream,ExtensionRegistryLite,int)
/home/orange/Documents/Dev/Project/Fastone/mgmt-api/build/generated/main/java/nott/v1/events/quota/Mgmt2StackQuota.java:1032: error: cannot find symbol
if (!super.parseUnknownField(input, extensionRegistry, tag)) {
^
symbol: method parseUnknownField(CodedInputStream,ExtensionRegistryLite,int)
/home/orange/Documents/Dev/Project/Fastone/mgmt-api/build/generated/main/java/nott/v1/events/quota/Mgmt2StackQuota.java:1915: error: cannot find symbol
if (!super.parseUnknownField(input, extensionRegistry, tag)) {
^
symbol: method parseUnknownField(CodedInputStream,ExtensionRegistryLite,int)
/home/orange/Documents/Dev/Project/Fastone/mgmt-api/build/generated/main/java/cmdb/v1/Cmdb.java:479: error: cannot find symbol
if (!super.parseUnknownField(input, extensionRegistry, tag)) {
^
symbol: method parseUnknownField(CodedInputStream,ExtensionRegistryLite,int)
/home/orange/Documents/Dev/Project/Fastone/mgmt-api/build/generated/main/java/cmdb/v1/Cmdb.java:1263: error: cannot find symbol
if (!super.parseUnknownField(input, extensionRegistry, tag)) {
^
symbol: method parseUnknownField(CodedInputStream,ExtensionRegistryLite,int)
/home/orange/Documents/Dev/Project/Fastone/mgmt-api/build/generated/main/java/cmdb/v1/Cmdb.java:2342: error: cannot find symbol
if (!super.parseUnknownField(input, extensionRegistry, tag)) {
^
symbol: method parseUnknownField(CodedInputStream,ExtensionRegistryLite,int)
/home/orange/Documents/Dev/Project/Fastone/mgmt-api/build/generated/main/java/cmdb/v1/Cmdb.java:3397: error: cannot find symbol
if (!super.parseUnknownField(input, extensionRegistry, tag)) {
^
symbol: method parseUnknownField(CodedInputStream,ExtensionRegistryLite,int)
/home/orange/Documents/Dev/Project/Fastone/mgmt-api/build/generated/main/java/cmdb/v1/Cmdb.java:4262: error: cannot find symbol
if (!super.parseUnknownField(input, extensionRegistry, tag)) {
^
symbol: method parseUnknownField(CodedInputStream,ExtensionRegistryLite,int)
/home/orange/Documents/Dev/Project/Fastone/mgmt-api/build/generated/main/java/cmdb/v1/Cmdb.java:4985: error: cannot find symbol
if (!super.parseUnknownField(input, extensionRegistry, tag)) {
^
symbol: method parseUnknownField(CodedInputStream,ExtensionRegistryLite,int)
/home/orange/Documents/Dev/Project/Fastone/mgmt-api/build/generated/main/java/cmdb/v1/Cmdb.java:5578: error: cannot find symbol
if (!super.parseUnknownField(input, extensionRegistry, tag)) {
^
symbol: method parseUnknownField(CodedInputStream,ExtensionRegistryLite,int)
/home/orange/Documents/Dev/Project/Fastone/mgmt-api/build/generated/main/java/cmdb/v1/Cmdb.java:6165: error: cannot find symbol
if (!super.parseUnknownField(input, extensionRegistry, tag)) {
^
symbol: method parseUnknownField(CodedInputStream,ExtensionRegistryLite,int)
/home/orange/Documents/Dev/Project/Fastone/mgmt-api/build/generated/main/java/cmdb/v1/Cmdb.java:9640: error: cannot find symbol
if (!super.parseUnknownField(input, extensionRegistry, tag)) {
^
symbol: method parseUnknownField(CodedInputStream,ExtensionRegistryLite,int)
12 errors

FAILURE: Build failed with an exception.

* What went wrong:
Execution failed for task ':compileJava'.
> Compilation failed; see the compiler error output for details.

* Try:
> Run with --stacktrace option to get the stack trace.
> Run with --info or --debug option to get more log output.
> Run with --scan to get full insights.

* Get more help at https://help.gradle.org

BUILD FAILED in 22s
9 actionable tasks: 9 executed

protobuf编译报错找不到proto文件

· 2 min read
orange
programmer on jvm platform

在新增submodule/api-contract/protobuf/node_manager/v1/srcDirs后, 编译报错, 编译输出如下

> Task :generateProto FAILED

FAILURE: Build failed with an exception.

* What went wrong:
Execution failed for task ':generateProto'.
> protoc: stdout: . stderr: nodemanager/v1/volume.proto: File not found.
nodemanager/v1/tag.proto: File not found.
nodemanager/v1/firewall.proto: File not found.
node.proto:10:1: Import "nodemanager/v1/volume.proto" was not found or had errors.
node.proto:11:1: Import "nodemanager/v1/tag.proto" was not found or had errors.
node.proto:12:1: Import "nodemanager/v1/firewall.proto" was not found or had errors.
node.proto:153:12: "Tag" is not defined.
node.proto:177:12: "VolumeSpec" is not defined.
node.proto:195:12: "Tag" is not defined.
node.proto:212:12: "Tag" is not defined.
node.proto:214:12: "RegisterVolumeSpec" is not defined.
node.proto:269:12: "Tag" is not defined.
node.proto:277:12: "nodemanager.v1.FirewallRule" seems to be defined in "firewall.proto", which is not imported by "node.proto". To use it here, please add the necessary import.
node.proto:299:12: "Volume" is not defined.


* Try:
> Run with --stacktrace option to get the stack trace.
> Run with --info or --debug option to get more log output.
> Run with --scan to get full insights.

* Get more help at https://help.gradle.org

BUILD FAILED in 4s
3 actionable tasks: 1 executed, 2 up-to-date

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))
}
}

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]