我正在尝试运行Spring Boot(使用Spring Cloud)+ Eureka Server + Hystrix Dashboard和Turbine流,但是我遇到了一个问题,到目前为止我找不到任何解决方案.我使用Spring Boot 1.2.1.RELEASE和Spring Cloud 1.0.0.RC2.这是我有的:
第一个实例是运行Eureka服务器和Hystrix仪表板:
@Configuration
@EnableAutoConfiguration
@EnableEurekaServer
@EnableHystrixDashboard
@EnableDiscoveryClient
class Application {
public static void main(String[] args) {
SpringApplication.run Application, args
}
}
Run Code Online (Sandbox Code Playgroud)
在这里你可以找到build.gradle该实例 - https://gist.github.com/wololock/570272ad7cf2d14a4d3c
Eureka服务器运行正常,我可以在eureka服务器仪表板上看到已注册的实例,我也可以LoadBalancer使用其ID来获取已注册实例的URL.到目前为止一切都很好.
我有一些使用@EnableHystrix注释运行的实例,@HystrixCommand用于定义Hystrix必须监视哪些方法.当我将URL传递给单个实例的hystrix.stream到Hystrix仪表板时,我可以看到它运行没有问题.
我也有单独的Turbine服务器,而不是复杂的服务器:
@EnableAutoConfiguration
@EnableTurbine
@Configuration
@EnableDiscoveryClient
class Application {
public static void main(String[] args) {
SpringApplication.run Application, args
}
}
Run Code Online (Sandbox Code Playgroud)
在这里您可以找到build.gradleTurbine服务器实例 - https://gist.github.com/wololock/ff0d855b8a890232851e
它使用非常简单的配置,主要基于样本涡轮应用程序提供的配置 - https://github.com/spring-cloud-samples/turbine
info:
component: Turbine
endpoints:
restart:
enabled: …Run Code Online (Sandbox Code Playgroud) 我无法解析验证消息.
我一直在搜索和阅读网络和SO几个小时,我想将问题与自定义弹簧验证错误的明确答案联系起来
我确实有一个MessageSourcebean定义并且messages.properties正确读取,因为我也使用它来显示常规文本th:text="#{some.prop.name},这确实很好用.只是验证错误不会以它应该的方式工作.我确定这是一个我忽略的愚蠢错误......验证本身工作正常.
约束:
@NotEmpty(message="{validation.mail.notEmpty}")
@Email()
private String mail;
Run Code Online (Sandbox Code Playgroud)
messages.properties:
# Validation
validation.mail.notEmpty=The mail must not be empty!
Run Code Online (Sandbox Code Playgroud)
模板部分:
<span th:if="${#fields.hasErrors('mail')}" th:errors="*{mail}"></span>
Run Code Online (Sandbox Code Playgroud)
显示的文字:
{validation.mail.notEmpty}
Run Code Online (Sandbox Code Playgroud)
我尝试了很多变化,都没有成功.
@NotEmpty(message="validation.mail.notEmpty")
@NotEmpty(message="#{validation.mail.notEmpty}")
Run Code Online (Sandbox Code Playgroud)
只显示消息字符串的确切值,无需解析.
<span th:if="${#fields.hasErrors('mail')}" th:errors="${mail}"></span>
<span th:if="${#fields.hasErrors('mail')}" th:errors="#{mail}"></span>
<span th:if="${#fields.hasErrors('mail')}" th:errors="#{*{mail}}"></span>
<span th:if="${#fields.hasErrors('mail')}" th:errors="#{__*{mail}__}"></span>
Run Code Online (Sandbox Code Playgroud)
会导致错误.
编辑:
经过调试,我偶然发现了这个问题:
类: org.springframework.context.support.MessageSourceSupport
方法: formatMessage(String msg, Object[] args, Locale locale)
将被召唤
formatMessage("{validation.mail.notEmpty}", null, locale /*German Locale*/)
它会遇到 if (messageFormat == INVALID_MESSAGE_FORMAT) {
所以...我的消息格式不正确.这超出了我的范围/知识.谁知道这意味着什么?
I have a Jenkinsfile with some global variables and some stages.
can I update the global variable out from a stage?
An example:
pipeline {
agent any
environment {
PASSWD = "${sh(returnStdout: true, script: 'python -u do_some_something.py')}"
ACC = "HI"
}
stage('stage1') {
when { expression { params.UPDATE_JOB == false } }
steps{
script {
def foo= sh( returnStdout: true, script: 'python -u do_something.py ')
env.ACC = foo
println foo
print("pw")
println env.PASSWD
}
}
}
}
Run Code Online (Sandbox Code Playgroud)
是否ACC可以使用foo中的值更新变量,以便我可以 …
我有一个声明詹金斯管道用stage1,stage2,stage3等。stage2如果stage1设置生成不稳定/失败,我想停止运行。
我知道我可以停止的步骤stage1使用运行return时版本是不是成功,但无法找到一种方法,我可以只退出管道不运行下面的阶段stage1
这是我所拥有的:
stage('stage1') {
steps {
script{
//somesteps
if ("${stdout}" == "1"){
currentBuild.result = 'UNSTABLE'
return
} //if
//somesteps
} //script
} //steps
} //stage
// run only when stage1 is success
stage('stage2'){
when {
expression {
params.name ==~ /x|y/
}
}
steps {
script{
//stage2 steps
}
}
}
Run Code Online (Sandbox Code Playgroud)
如果params.name ==~ /z/将执行阶段3,则跳过阶段2
注意:我不能在stage1的stage2 / 3 / ..中包括这些步骤。应该是那样的。根据构建参数,stage2 / 3/4 ...将在stage1之后调用
我有一个Spring Boot(1.2.1.RELEASE)应用程序,它在一个应用程序实例中提供OAuth2(2.0.6.RELEASE)授权和资源服务器.它使用自定义UserDetailsService实现MongoTemplate来搜索MongoDB中的用户.使用grant_type=passwordon进行身份验证/oauth/token就像魅力一样,以及Authorization: Bearer {token}在调用特定资源时使用标头进行授权.
现在我想向服务器添加简单的OAuth确认对话框,因此我可以在api-docs中对受保护资源进行身份验证和授权,例如Swagger UI调用.这是我到目前为止所做的:
@Configuration
@SessionAttributes("authorizationRequest")
class OAuth2ServerConfig extends WebMvcConfigurerAdapter {
@Override
public void addViewControllers(ViewControllerRegistry registry) {
registry.addViewController("/login").setViewName("login");
registry.addViewController("/oauth/confirm_access").setViewName("authorize");
}
@Configuration
@Order(2)
protected static class LoginConfig extends WebSecurityConfigurerAdapter implements ApplicationEventPublisherAware {
@Autowired
UserDetailsService userDetailsService
@Autowired
PasswordEncoder passwordEncoder
ApplicationEventPublisher applicationEventPublisher
@Bean
DaoAuthenticationProvider daoAuthenticationProvider() {
DaoAuthenticationProvider provider = new DaoAuthenticationProvider()
provider.passwordEncoder = passwordEncoder
provider.userDetailsService = userDetailsService
return provider
}
@Override
protected void configure(AuthenticationManagerBuilder auth) throws Exception …Run Code Online (Sandbox Code Playgroud) 如果我们知道数据类型并且它不会在运行时更改,我们是否应该定义变量的数据类型或方法的返回类型?有什么利弊或使用def vs实际数据类型?
一个例子是,如果abc是打算的话 List<String>
List<String> abc = "xyz"; //IntelliJ IDEA gives syntax highlighting for improper assignment
def abc = "xyz"; //IntelliJ IDEA will not give syntax highlighting
Run Code Online (Sandbox Code Playgroud) 我在网上找不到直接的答案.
Spring Boot的yml文件是否相互"继承"?我的意思是,如果我有:
application.yml哪个
server:
port: 80
host: foo
Run Code Online (Sandbox Code Playgroud)
而且application-profile1.yml只有
server:
port: 90
Run Code Online (Sandbox Code Playgroud)
因此,如果我使用profile1活动配置文件启动Spring Boot ,我是否也将server.host属性设置为foo?
如何将8080Micronaut 中的默认端口更改为其他端口?我在我的项目中使用了 Micronaut,我找不到更改端口号的配置。
我有一个通用的私有方法,它执行常见的任务,并由其他方法使用.通用方法if和else条件,支持被调用的其他方法.例:
private void myGenericMethod(String name, int age){
common task1;
common task2;
if(name!= null && name.length > 0){
specific task 1;
specific task 2;
} else{
specific task 3;
specific task 4;
}
if(age > 18){
specific task 1`;
specific task 2`;
}
}
Run Code Online (Sandbox Code Playgroud)
我想使用Java 8 lambda,我创建了一个Invoker用invoke方法调用的函数接口.
public interface Invoker{
public void invoke()
}
Run Code Online (Sandbox Code Playgroud)
现在我的泛型方法看起来像这样,公共方法适当地处理调用函数回调:
private void myGenericMethod(Invoker invoker){
common task1;
common task2;
invoker.invoke();
}
Run Code Online (Sandbox Code Playgroud)
我可以使用JDK中的功能接口而不是自己创建这个接口吗?
是否可以在mapToObj方法中执行多个语句?.假设我想使用以下代码将字符串转换为二进制字符串:
String str = "hello";
String bin = str.chars()
.mapToObj(x-> Integer.toBinaryString(x))
.collect(Collectors.joining(" "));
Run Code Online (Sandbox Code Playgroud)
但是,我想使用类似的东西处理前导零
String.format("%8s", x).replaceAll(" ", "0")
Run Code Online (Sandbox Code Playgroud)
那么,如何在mapToObj方法中添加它.我是Java 8新功能的新手.任何帮助,将不胜感激
groovy ×4
spring-boot ×4
java ×2
java-8 ×2
jenkins ×2
generics ×1
hystrix ×1
java-stream ×1
lambda ×1
micronaut ×1
spring ×1
spring-cloud ×1
thymeleaf ×1
turbine ×1