在 Spring Boot 2.2.0 中,“httptrace”Actuator 端点不再存在。我怎样才能恢复这个功能?
我的带有 Spring Web MVC 的 Spring Boot 2.2.0 应用程序在反向代理后面运行。Spring 如何正确处理X-Forwarded-{Prefix,Host,Proto}
-headers 以识别向服务器发出的实际请求?
我有个问题.我想在日志文件中记录特定情况下的回溯.debug_print_backtrace()
为我的目的构建一个正确的字符串,但debug_print_backtrace()
在屏幕上打印跟踪而不是返回它.
有任何想法吗?
我不确定它是否tokio
类似于 Javascript 中的事件循环,也是一个非阻塞运行时,或者它是否可以用于以类似的方式工作。以我的理解,tokio
是 Rust 中 future 的运行时。因此,它必须实现某种用户态线程或任务,这可以通过事件循环(至少部分)来调度新任务来实现。
我们来看下面的 Javascript 代码:
console.log('hello1');
setTimeout(() => console.log('hello2'), 0);
console.log('hello3');
setTimeout(() => console.log('hello4'), 0);
console.log('hello5');
Run Code Online (Sandbox Code Playgroud)
输出将是
hello1
hello3
hello5
hello2
hello4
Run Code Online (Sandbox Code Playgroud)
我怎样才能在东京做到这一点?tokio 总体上是这样工作的吗?我尝试了以下代码
async fn set_timeout(f: impl Fn(), ms: u64) {
tokio::time::sleep(tokio::time::Duration::from_millis(ms)).await;
f()
}
#[tokio::main]
async fn main() {
println!("hello1");
tokio::spawn(async {set_timeout(|| println!("hello2"), 0)}).await;
println!("hello3");
tokio::spawn(async {set_timeout(|| println!("hello4"), 0)}).await;
println!("hello5");
}
Run Code Online (Sandbox Code Playgroud)
输出只是
hello1
hello3
hello5
Run Code Online (Sandbox Code Playgroud)
如果我将代码更改为
println!("hello1");
tokio::spawn(async {set_timeout(|| println!("hello2"), 0)}.await).await;
println!("hello3");
tokio::spawn(async {set_timeout(|| println!("hello4"), 0)}.await).await;
println!("hello5");
Run Code Online (Sandbox Code Playgroud)
输出是
hello1
hello2 …
Run Code Online (Sandbox Code Playgroud) 我正面临 angular2 软件设计问题,我不知道什么是更好的解决方案:
在 ngOnInit 中获取 REST 数据还是使用解析器?
我从来没有遇到过在 ngOnInit 方法中获取数据的问题,但现在我听说过解析器,但我不确定要使用什么:
ngOnInit() {
this.authHttp.get('http://localhost:8080/configuration')
.map((response: Response) => <ConfigurationData>response.json())
.subscribe(settings => this.settings = settings);
}
Run Code Online (Sandbox Code Playgroud)
对比
@Injectable()
export class ConfigurationsResolver implements Resolve<ConfigurationData> {
constructor(private authHttp: AuthHttp) {}
public resolve(route: ActivatedRouteSnapshot): Observable<ConfigurationData> {
return this.authHttp.get('http://localhost:8080/configuration')
.map((response: Response) => <ConfigurationData>response.json());
}
}
Run Code Online (Sandbox Code Playgroud)
解析器会产生更多的代码。额外的类,声明一个提供者等等。
所以你怎么看?关于此的任何声明和最佳实践?
根据我的了解,我应该始终选择Arc<T>
跨线程共享读访问和跨线程Arc<Mutex<T>>
共享写访问。在某些情况下,我不想使用Arc<T>
/Arc<Mutex<T>>
而是做一些完全不同的事情吗?例如做这样的事情:
unsafe impl Sync for MyStruct {}
unsafe impl Send for MyStruct {}
let shared_data_for_writing = Arc::from(MyStruct::new());
Run Code Online (Sandbox Code Playgroud) 我正在开发 Spring REST 服务(使用 Spring Data JPA),并且我的实体包含 java.util.UUID 类型的属性。我使用MySQL作为数据库,这会导致问题。到目前为止,除了 UUID 是查询一部分的存储库方法之外,一切都工作正常,例如: entityRepository.findByUuid(UUID uuid);
默认情况下,数据存储在二进制 (255) 列中。从存储库获取 UUID 工作正常,唯一的问题是在查询中使用 UUID,如 findByUuid() 中。它总是告诉我在数据库中找不到特定的 UUID。MariaDB 也会出现同样的问题。
我的服务与 H2-Database 一起正常工作。知道为什么 MySQL(和 MariaDB)有这个问题吗?
数据库配置:
spring.datasource.url=jdbc:mysql://localhost/abc123
spring.datasource.username=alfkmakfaf
spring.datasource.password=aafkmafmlaf
spring.datasource.driver-class-name=com.mysql.jdbc.Driver
spring.jpa.database=mysql
spring.jpa.hibernate.ddl-auto=update
spring.jpa.properties.hibernate.dialect = org.hibernate.dialect.MySQL5Dialect
Run Code Online (Sandbox Code Playgroud)
实体中的 UUID
@Entity
public class Thema {
// without any annotations, works fine with H2 Database
private UUID uuid;
...
Run Code Online (Sandbox Code Playgroud) 我正在编写 Rust 代码,需要获取当前存储在“ebx”寄存器(x86)内的值。
我的代码 [0] 如下所示:
#![feature(asm)]
fn main() {
let ebx: u32;
unsafe { asm!("", out("ebx") ebx) };
println!("current value of register ebx is: {}", ebx);
}
Run Code Online (Sandbox Code Playgroud)
rustc 1.54.0-nightly 的错误代码是:
invalid register `ebx`: rbx is used internally by LLVM and cannot be used as an operand for inline asm
Run Code Online (Sandbox Code Playgroud)
我发现的唯一可行的解决方法是传统方式:
unsafe {
llvm_asm!("" : "={ebx}"(ebx) : :);
}
Run Code Online (Sandbox Code Playgroud)
有没有办法用新的asm!
宏来实现所需的功能?
PS:由于我的研究,我发现了这个: https: //github.com/rust-lang/rust/pull/84658。但它仍然没有提供一个很好且简单的解决方案。
我为 const 泛型类型提供默认值,但 Rust 编译器告诉我它“无法推断 const 参数的值”。似乎忽略了默认值。我使用这个功能有错吗?这是它应该如何工作的吗?那么为什么要使用默认值呢?我用的是每晚1.60。
const DEFAULT_N: usize = 73;
struct Foo<const N: usize = DEFAULT_N>;
impl<const N: usize> Foo<N> {
fn new() -> Self {
println!("N is: {}", N);
Self
}
}
fn main() {
Foo::new();
}
Run Code Online (Sandbox Code Playgroud) 对于现在的一些 Rust 版本,人们可以这样做_ = foo()
而不是let _ = foo()
在作业中。但是,我不记得这个语法的名称,也找不到它的官方文档。我在 rustlang 仓库中也没有找到 PR。有人可以提供一些背景吗?
rust ×5
spring-boot ×2
angular ×1
async-await ×1
debugging ×1
hibernate ×1
java ×1
logging ×1
mysql ×1
php ×1
rust-tokio ×1
spring ×1
spring-mvc ×1