我在我的项目中添加了 spring-cloud-starter-netflix-eureka-client gradle 依赖项并取消了依赖项。但是,当在我的主类中使用 @EnableEurekaClient 时,它会向我显示建议创建 @EnableEurekaClient 注释。不显示eureka客户端的任何导入文件。
Unresolved reference: EnableEurekaClient
Run Code Online (Sandbox Code Playgroud)
产品服务应用程序.kt
package com.main.productservice
import org.springframework.boot.autoconfigure.SpringBootApplication
import org.springframework.boot.runApplication
@SpringBootApplication
@EnableEurekaClient
class ProductServiceApplication
fun main(args: Array<String>) {
runApplication<ProductServiceApplication>(*args)
}
Run Code Online (Sandbox Code Playgroud)
gradle.kt
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"
}
group = "com.main"
version = "0.0.1-SNAPSHOT"
java.sourceCompatibility = JavaVersion.VERSION_11
repositories {
mavenCentral()
}
dependencies {
implementation("org.springframework.boot:spring-boot-starter-data-mongodb")
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-starter-netflix-eureka-client")
testImplementation("org.springframework.boot:spring-boot-starter-test")
}
tasks.withType<KotlinCompile> {
kotlinOptions {
freeCompilerArgs = listOf("-Xjsr305=strict")
jvmTarget = "11" …Run Code Online (Sandbox Code Playgroud) kotlin spring-boot spring-cloud netflix-eureka spring-cloud-netflix
我只是想使用协议缓冲区为 golang 生成代码。但无法使用 protoc 命令生成服务。
syntax = "proto3";
package greet;
option go_package="./greet/greetpb";
service GreetService{}
Run Code Online (Sandbox Code Playgroud)
上面是一个虚拟的原始文件,我正在尝试将其转换为 golang。但无法生成正确的文件,因为在我的系统中它无法将service GreetService{} 线路识别为服务。
我在Windows系统上使用以下版本的protoc:
PS D:\Study\grpc\go-grpc-course> protoc --version
libprotoc 3.17.3
Run Code Online (Sandbox Code Playgroud)
使用以下命令生成代码:
协议 .\greet\greetpb\greet.proto --go_out=.
下面是上面命令生成的go代码:
// Code generated by protoc-gen-go. DO NOT EDIT.
// versions:
// protoc-gen-go v1.26.0
// protoc v3.17.3
// source: greet/greetpb/greet.proto
package greetpb
import (
protoreflect "google.golang.org/protobuf/reflect/protoreflect"
protoimpl "google.golang.org/protobuf/runtime/protoimpl"
reflect "reflect"
)
const (
// Verify that this generated code is sufficiently up-to-date.
_ = protoimpl.EnforceVersion(20 - protoimpl.MinVersion)
// Verify that …Run Code Online (Sandbox Code Playgroud) 这是将 @Bean 与静态方法一起使用的好习惯吗?
public class Foo {
}
Run Code Online (Sandbox Code Playgroud)
@Configuration
public FooFactory {
@Bean
public static Foo getFoo() {
return new Foo();
}
}
Run Code Online (Sandbox Code Playgroud) 我有一个 Spring Boot 应用程序,它通过 Spring Cloud 从远程配置服务器读取属性,并且它可以与远程存储库中定义的不同配置文件配合使用,我使用以下命令运行它:
java -jar my-app.jar --spring.profiles.active=my-custom-profile
Run Code Online (Sandbox Code Playgroud)
但是,在某些特殊情况下,我希望能够在更改某些远程属性的同时运行应用程序(这些更改不是固定的,因此我无法为它们创建一些自定义配置文件),因此我尝试覆盖直接通过命令行进行操作:
java -jar my-app.jar --spring.profiles.active=my-custom-profile --my.first.property=value1 --my.second.property=value2
Run Code Online (Sandbox Code Playgroud)
但似乎没有考虑到这一点,因为应用程序在启动时仍然采用远程属性。
有没有适当的方法来实现这一目标?
我有以下上传控制器,它有两个不同类型的参数:1 用于保存文件的路径,2 用于文件本身。我正在寻找正确的方法定义,而不是 2 个在 STS 中给出错误的 @Requestparam。
@PostMapping("/{path}/")
public String handleFileUpload(@RequestParam("path"), @RequestParam("file") MultipartFile file,
RedirectAttributes redirectAttributes) {
filesStorageService.store(file);
redirectAttributes.addFlashAttribute("message", "You successfully uploaded " + file.getOriginalFilename() + "!");
return "redirect:/";
}
Run Code Online (Sandbox Code Playgroud) spring-boot ×3
java ×2
spring ×2
spring-cloud ×2
go ×1
kotlin ×1
proto ×1
protoc ×1
rest ×1
spring-bean ×1