package com.main.inventoryservice.controller
import com.main.inventoryservice.model.Inventory
import com.main.inventoryservice.repository.InventoryRepository
import lombok.RequiredArgsConstructor
import lombok.extern.slf4j.Slf4j
import org.springframework.beans.factory.annotation.Autowired
import org.springframework.web.bind.annotation.*
import java.util.*
@RestController
@RequestMapping("/inventory")
@RequiredArgsConstructor
@Slf4j
class InventoryController {
@Autowired
private lateinit var inventoryRepository: InventoryRepository
@GetMapping("/{skuCode}")
fun isInStock(@PathVariable skuCode: String): Boolean? {
log.info("Checking stock for product with skucode - $skuCode")
val (_, _, stock) = inventoryRepository.findBySkuCode(skuCode)
.orElseThrow { RuntimeException("Cannot Find Product by sku code $skuCode") }
return stock!! > 0
}
}
log.info("Checking stock for product with skucode - $skuCode")
unresolved refrence :log
import org.jetbrains.kotlin.gradle.tasks.KotlinCompile
plugins {
id("org.springframework.boot") version "2.5.2"
id("io.spring.dependency-management") version "1.0.11.RELEASE"
kotlin("jvm") version "1.5.20"
kotlin("plugin.spring") version "1.5.20"
kotlin("plugin.jpa") version "1.5.20"
}
group = "com.main"
version = "0.0.1-SNAPSHOT"
java.sourceCompatibility = JavaVersion.VERSION_11
repositories {
mavenCentral()
}
extra["springCloudVersion"] = "2020.0.3"
dependencies {
implementation("org.springframework.boot:spring-boot-starter-amqp")
implementation("org.springframework.boot:spring-boot-starter-data-jpa")
implementation("org.springframework.boot:spring-boot-starter-oauth2-resource-server")
implementation("org.springframework.boot:spring-boot-starter-security")
implementation("org.springframework.boot:spring-boot-starter-web")
implementation("com.fasterxml.jackson.module:jackson-module-kotlin")
implementation("org.jetbrains.kotlin:kotlin-reflect")
implementation("org.jetbrains.kotlin:kotlin-stdlib-jdk8")
implementation("org.springframework.cloud:spring-cloud-sleuth-zipkin")
implementation("org.springframework.security:spring-security-oauth2-jose:5.4.6")
implementation("org.springframework.cloud:spring-cloud-starter")
implementation("org.springframework.cloud:spring-cloud-stream-binder-rabbit:3.1.3")
implementation("org.springframework.cloud:spring-cloud-starter-bus-amqp:3.0.2")
implementation("org.springframework.cloud:spring-cloud-starter-config")
implementation("net.logstash.logback:logstash-logback-encoder:6.6")
implementation("org.springframework.cloud:spring-cloud-starter-sleuth")
runtimeOnly("mysql:mysql-connector-java")
compileOnly("org.projectlombok:lombok")
annotationProcessor("org.projectlombok:lombok")
testImplementation("org.springframework.boot:spring-boot-starter-test")
testImplementation("org.springframework.amqp:spring-rabbit-test")
testImplementation("org.springframework.security:spring-security-test")
}
dependencyManagement {
imports {
mavenBom("org.springframework.cloud:spring-cloud-dependencies:${property("springCloudVersion")}")
}
}
tasks.withType<KotlinCompile> {
kotlinOptions {
freeCompilerArgs = listOf("-Xjsr305=strict")
jvmTarget = "11"
}
}
tasks.withType<Test> {
useJUnitPlatform()
}
我想通过日志打印一些消息,所以我使用log.info(),但它不工作,并在日志内容上显示错误
您应该使用java.util.logging.logger
:
>
导入:
import java.util.logging.Logger;
创建:
class YourClass {
private static final Logger logger = Logger.getLogger("MyLogger");
}
class YourClass {
private static final Logger logger = Logger.getLogger("MyLogger");
public void some() {
logger.severe(":(");
logger.warning(":|");
logger.info(":)");
}
}
我遇到了一个错误 导入语句如下所示 Kotlin版本:1.1.51 提前致谢:)
我正在Android Studio中尝试Kotlin和Kotlin Android扩展。我在Ubuntu 14.04上的Android Studio v1.5.1和OS X El Capitan上的Android Studio v1.5.1中都进行了尝试,得到了相同的结果。 下面是我正在做的事情: null 然后进入生成的content_main.xml文件,并为“hello World!”添加一
我试图使用新的相机硬件API(android.hardware.camera2)的示例代码为我的Android应用程序。首先,我通过Android Studio的静态编程语言插件的自动转换功能将Java代码转换为静态编程语言代码。下面是一段转换后的代码: 我得到了未解决的引用错误: 但是这些常数在原始Java代码中是可以识别的。这些错误有什么解决办法吗?