我正在尝试将值的输出转换为整数:
@Value("${api.orders.pingFrequency}")
private Integer pingFrequency;
Run Code Online (Sandbox Code Playgroud)
以上抛出错误
org.springframework.beans.TypeMismatchException:
Failed to convert value of type 'java.lang.String' to required type 'java.lang.Integer';
nested exception is java.lang.NumberFormatException:
For input string: "(java.lang.Integer)${api.orders.pingFrequency}"
Run Code Online (Sandbox Code Playgroud)
我也试过了 @Value("(java.lang.Integer)${api.orders.pingFrequency}")
谷歌似乎没有多说这个话题.我想总是处理一个整数,而不是必须在它使用的任何地方解析这个值.
解决方法
我意识到一个解决方法可能是使用setter方法为我运行转换,但如果Spring可以做到这一点,我宁愿学习一些关于Spring的东西.
我能够访问端点一样http://localhost:8081/health
,/status
,/env
,/metrics
,/shutdown
但没有 /actuator
或/loginfo
端点.
低于例外.
{"timestamp":1455929182552,"status":404,"error":"Not Found","message":"No message available","path":"/actuator"}
Run Code Online (Sandbox Code Playgroud)
如何访问http:// localhost:8081 /执行器端点?
我有一个spring mvc控制器,我想只在某些配置文件中启用它(例如development
和test
).
我知道我可以在xml配置中使用元素的profile
属性beans
来限制我的bean的范围,但我现在正在为控制器使用方便的注释.
我可以以某种方式将带注释的控制器绑定到给定的配置文件吗?
或者我是否必须使用"旧方法"(实现和声明控制器)而不使用注释并beans
在xml配置中使用该元素?
带注释的控制器是否会与"旧的控制器"很好地混合?
编辑:另一种方式,我想到的是从自动装配的环境实例检查运行时的配置文件,但这否定了控制的反转
我正在尝试使用命令从 Ubuntu 18.04.2 LTS 中的终端运行 Intellij IDEA 2019.2 idea
。
但终端保持连接到 IDEA 输出 - IDEA 将日志写入其中。
我尝试使用&
: idea &
,但没有帮助 - 控制台仍然连接到 IDEA。
romach@romach:~/bin$ idea &
[2] 836
romach@romach:~/bin$ 2019-08-01 15:55:56,253 [ 1189] WARN - llij.ide.plugins.PluginManager - Docker integration not loaded: until build 182.SNAPSHOT < IU-192.5728.98
2019-08-01 15:55:56,296 [ 1232] WARN - llij.ide.plugins.PluginManager - NodeJS not loaded: until build 191.SNAPSHOT < IU-192.5728.98
2019-08-01 15:55:56,865 [ 1801] WARN - llij.ide.plugins.PluginManager - Docker integration not loaded: until build 182.SNAPSHOT < …
Run Code Online (Sandbox Code Playgroud) 我有这个Gradle依赖项的Spring Boot应用程序:
compile("org.springframework.cloud:spring-cloud-starter-eureka")
compile("org.springframework.cloud:spring-cloud-starter-feign")
compile("org.springframework.cloud:spring-cloud-starter-ribbon")
compile("org.springframework.cloud:spring-cloud-starter-hystrix")
compile("org.springframework.cloud:spring-cloud-starter-config")
Run Code Online (Sandbox Code Playgroud)
我也有Feign客户端:
@FeignClient(name = "client")
public interface FeignService {
@RequestMapping(value = "/path", method = GET)
String response();
}
Run Code Online (Sandbox Code Playgroud)
我的application.properties
:
client.ribbon.listOfServers = http://localhost:8081
ribbon.eureka.enabled=false
Run Code Online (Sandbox Code Playgroud)
当查询时间超过1秒时,我得到异常:
com.netflix.hystrix.exception.HystrixRuntimeException: response timed-out and no fallback available.
Run Code Online (Sandbox Code Playgroud)
所以我的问题是:如何设置自定义Feign客户端连接超时?例如2秒.
我想DefaultHandlerExceptionResolver
在我的 Spring Boot 应用程序中进行自定义,但在发生异常时从未达到自定义实现。
构建.gradle
buildscript {
ext {
springBootVersion = '2.1.1.RELEASE'
}
repositories {
mavenCentral()
}
}
plugins {
id 'java'
id 'org.springframework.boot' version '2.1.1.RELEASE'
id 'io.spring.dependency-management' version '1.0.6.RELEASE'
id 'io.franzbecker.gradle-lombok' version '1.14'
}
lombok {
version = '1.18.4'
sha256 = ""
}
group = 'ua.com.javaman'
version = '0.0.1-SNAPSHOT'
sourceCompatibility = 1.8
repositories {
mavenCentral()
}
dependencies {
implementation('org.springframework.boot:spring-boot-starter-web')
}
Run Code Online (Sandbox Code Playgroud)
应用程序.java
buildscript {
ext {
springBootVersion = '2.1.1.RELEASE'
}
repositories {
mavenCentral()
}
}
plugins {
id …
Run Code Online (Sandbox Code Playgroud) 如何使用ResultSetExtractor
从数据库中检索数据?在这里我使用oracle 10g作为后端.如果从员工表中搜索员工详细信息哪一个更好用,ResultSetExtractor
或者RowMapper
?
我是Java新手.
我正在制作这个教程(Spring MVC + Hibernate + Tomcat)
到目前为止,一切都很好.当我试图制作一个ApplicationController
我无法自动装配的时候ApplicationRepository
.
404
部署应用程序时,我收到此错误消息和错误代码:
Could not autowire. No beans of 'ApplicationRepository' type found. less...
(Ctrl+F1)
Checks autowiring problems in a bean class.
Run Code Online (Sandbox Code Playgroud)
好的谈话很便宜.
这里是repo(github!):https://github.com/maciejkowalski/sample-spring-app
Tomcat 堆栈跟踪:https://gist.github.com/maciejkowalski/c7512d82feb75fcebd5f
这是代码:
根/ SRC /主/爪哇/ wzpweb /
package wzpweb;
import javax.persistence.*;
@Entity(name = "applications")
public class Application {
@Id
@GeneratedValue(strategy = GenerationType.AUTO)
private Long id;
@Basic
private String name;
@Basic
private String …
Run Code Online (Sandbox Code Playgroud) 我有两个 Spring Boot 应用程序:
cloud-config
它具有以下文件结构:
????src
????main
????environment
????default
????application.yml
????bootstrap.yml
...
Run Code Online (Sandbox Code Playgroud)
application.yml
:
server:
port: 8087
spring:
cloud:
config:
server:
git:
uri: ssh://path-to-repository.git
Run Code Online (Sandbox Code Playgroud)
bootstrap.yml
:
spring:
application:
name: cloud-config
Run Code Online (Sandbox Code Playgroud)main-application
:
????src
????main
????environment
????default
????bootstrap.yml
????logback.xml
Run Code Online (Sandbox Code Playgroud)
我有application.yml
我main-application
的 git 存储库。
同样在 git 存储库中,我有一个带有属性的文件:application-default.properties
.
我想转移logback.xml
到 git 存储库以使用 spring-cloud 获取它。我怎样才能做到这一点?
我想格式化 Ansible 输出:
my_local | SUCCESS | rc=0 >>
116G
my_local2 | SUCCESS | rc=0 >>
116G
Run Code Online (Sandbox Code Playgroud)
到
my_local >> 116G
my_local2 >> 116G
Run Code Online (Sandbox Code Playgroud)
是否可以?
inventory.ini
:
my_local ansible_connection=local
my_local2 ansible_connection=local
Run Code Online (Sandbox Code Playgroud)
重击命令:
ansible all -i inventory.ini -u root -m shell -a "df -h / | tail -1 | awk '{print \$4}'"
Run Code Online (Sandbox Code Playgroud) spring ×6
java ×5
spring-boot ×3
spring-mvc ×3
annotations ×1
ansible ×1
casting ×1
feign ×1
hibernate ×1
hystrix ×1
jpa ×1
logback ×1
spring-cloud ×1
spring-jdbc ×1