@GetMapping(path = "/cars", produces = "text/event-stream")
public Flux<Car> getCarStream() {
System.out.println("application/stream+json");
return this.repository.findCarsBy().log();
}
Run Code Online (Sandbox Code Playgroud)
上面的代码和下面的有什么区别:
@GetMapping(path = "/cars", produces = "application/stream+json")
public Flux<Car> getCarStream() {
System.out.println("application/stream+json");
return this.repository.findCarsBy().log();
}
Run Code Online (Sandbox Code Playgroud)
到目前为止,我发现了矛盾的信息:有人说它们都表示服务器发送的事件,而其他人则表示存在差异。
这是一行将文件读入List
:
List<String> lines =
new BufferedReader(
new InputStreamReader(classLoader.getResourceAsStream(fileName)))
.lines()
.collect(Collectors.toList());
Run Code Online (Sandbox Code Playgroud)
这是正确的还是应该将BufferedReader
变量分配给变量以便以后关闭它?
在哪种情况下我应该使用每一个?
文档说:
为文字创建表达式
在代码中我看到了cb.literal()的此类用法:
Expression<String> wordLiteral = cb.literal(word);
predicates.add(cb.like(namePath, wordLiteral));
Run Code Online (Sandbox Code Playgroud)
但如果这里省略wordLiteral并使用word代替,则不会发生任何变化。那么这个方法是做什么用的呢?
为什么端口有两个名称?
server.port=..
Run Code Online (Sandbox Code Playgroud)
和
local.server.port
Run Code Online (Sandbox Code Playgroud)
它们之间有什么区别?
您能帮助我在公开 REST 服务的 Spring Boot 应用程序中进行安全配置吗:我有JWTAuthenticationFilter extends UsernamePasswordAuthenticationFilter
,JWTAuthorizationFilter extends BasicAuthenticationFilter
以及以下configure
方法WebSecurityConfig extends WebSecurityConfigurerAdapter
:
protected void configure(HttpSecurity http) throws Exception {
http.cors().and().csrf().disable().authorizeRequests().antMatchers(HttpMethod.POST, SIGN_UP_URL).permitAll()
.anyRequest().authenticated().and().addFilter(new JWTAuthenticationFilter(authenticationManager()))
.addFilter(new JWTAuthorizationFilter(authenticationManager()))
.sessionManagement().sessionCreationPolicy(SessionCreationPolicy.STATELESS);
}
Run Code Online (Sandbox Code Playgroud)
现在,当 Jwt 令牌过期时,会返回错误 500。如何以及在哪里让它返回 401?
我已经看到不同的属性delimeters:=无法找到它的参考.
我有一个 Spring Boot 应用程序,它为 Angular Web 界面提供 REST API。
此 Spring Boot 应用程序中当前还有一个预定作业。这项工作是用一些实体填充数据库,比如说书籍(它们取自外部来源,更具体地说,取自网站)。我想将这项工作放入一个单独的微服务中。
问题是微服务是否应该直接使用共享数据库或通过 REST 访问主应用程序。在第一种情况下,一些(如果不是全部)模型和服务将被共享,这看起来不太好。但在第二种情况下,每次对数据库的访问都将通过第一个应用程序。这可以吗?
应用程序中有一些users
有偏好的内容 - 最喜欢的作者。用户可以更改此列表。作者位于实体authors
的集合中User
:
@Entity
public class User {
@Id
....
@ElementCollection
private List<String> authors=new ArrayList<>();
}
Run Code Online (Sandbox Code Playgroud)
用户可以编辑他的个人资料并通过添加或删除作者来更改此列表。一方面,添加或删除作者意味着只需编辑个人资料,这就是我目前使用以下PUT
方法的原因:
@PutMapping("/api/profile/author/add")
@PutMapping("/api/profile/author/remove")
Run Code Online (Sandbox Code Playgroud)
但我不确定这是否正确。另一种变体是在用户添加和删除项目时使用POST
和方法:DELETE
@PostMapping("/api/profile/author/add")
@DeleteMapping("/api/profile/author/remove")
Run Code Online (Sandbox Code Playgroud)
那么什么是正确的变体,原因是什么?