如何在Spring 5 Webflux项目中启用CORS?
我找不到任何适当的文件.
在我设置的Spring Boot App(2.0.0.M7)application.properties中
management.endpoint.metrics.enabled=true
Run Code Online (Sandbox Code Playgroud)
但是,当我击中时
localhost:8080/actuator/metrics
Run Code Online (Sandbox Code Playgroud)
我得到404.
什么是解决方案?
我有一个SpringBoot应用程序,我有一个配置包
@Configuration
@EnableJpaAuditing
public class PersistenceConfig {
}
Run Code Online (Sandbox Code Playgroud)
但PersistenceConfig不会在PersonRepositoryTest中被捕获
@RunWith( SpringRunner.class )
@DataJpaTest
public class PersonRepositoryTest {
// Tests ...
}
Run Code Online (Sandbox Code Playgroud)
但是,如果我改变@DataJpaTest to @SpringBootTest,PersonRepositoryTest将获取配置.
我的包结构是
- main
- java
- config
PersistenceConfig.java
- domain
Person.java
- persistence
PersonRepository.java
Application.java // @SpringBootApplication
- test
- java
- persistence
PersonRepositoryTest.java
Run Code Online (Sandbox Code Playgroud)
Spring Boot 1.4中的测试改进建议使用@DataJpaTest测试持久层
观察: 在Test类上执行两个注释仍然不导入config @SpringBootTest @DataJpaTest
问题1: 使用@DataJpaTest测试持久层时如何正确(Spring Boot中的最佳实践方式)将配置包导入我的测试?
问题2: 使用@SpringBootTest是否可以接受?我知道@DataJpaTest也是一个元注释,我的数据库有合理的自动配置,包括事务管理.但如果我不需要呢?
configuration spring unit-testing spring-data-jpa spring-boot
我在User和GameMap之间有一对多的关系.一个用户可以拥有许多地图.
用户类:
// LAZY LOADED
@OneToMany(cascade = CascadeType.ALL, mappedBy = "creater")
private final List<GameMap> maps = new ArrayList<>();
Run Code Online (Sandbox Code Playgroud)
但是,有时我需要急于加载地图.为了避免在关闭Session之后出现LazyInitializationException,我有两种检索用户的变体.
用户存储库:
public interface UserRepository extends JpaRepository<User, Long> {
Optional<User> findById( Long id );
@Query("SELECT u FROM User u JOIN FETCH u.maps WHERE u.id = (:id)")
public User findByIdEagerFetch( @Param("id") Long id );
}
Run Code Online (Sandbox Code Playgroud)
问题:
但是,如果表中没有此用户的映射,则JPQL JOIN FETCH变量可以在一个用户中执行,并且如果该用户没有映射,则他的映射将返回NULL用户.
问题:
如何重写JPQL语句以便检索用户并可选地(!)所有他的地图,但如果没有地图,那可以,但不要返回NULL用户.
I am aware of how to retrieve eg. a video stream from a webcam source:
const constraints = { video: true };
navigator.mediaDevices
.getUserMedia(constraints)
.then(mediaStream => {
// ** But how to get the a stream of bytes from here??? **
});
Run Code Online (Sandbox Code Playgroud)
I could not find any proper documentation of how to retrieve a stream of bytes from the mediaStream object.
How to do this? Because, lets say I want to stream the bytes to the server.
可以说我有
inline class CustomId(val id: String)
Run Code Online (Sandbox Code Playgroud)
我使用 Jackson 将它反序列化回一个对象,Jackson 抛出一个异常:
无效定义异常
Cannot construct instance of CustomId (no Creators, like default construct, exist)
如何解决这个问题呢?
如何创建自定义解串器?
我是否理解正确,为了在 Spring MVC 应用程序中捕获/数据绑定 HTTP 请求的主体,有人可以使用...
@RequestBody
application/json对于编码为?的请求
@PostMapping(consumes = "application/json")
public String handleUpload( @RequestBody UploadCommand command ) {
// ...
}
Run Code Online (Sandbox Code Playgroud)
@ModelAttribute
x-www-form-urlencoded对于编码为或multipart/form-data?的请求
@PostMapping(consumes = "multipart/form-data")
public String handleUpload( @ModelAttribute UploadCommand command ) {
// ...
}
Run Code Online (Sandbox Code Playgroud)
问题:
为什么Spring需要有这两个不同的注解呢?
这些注释还有其他用例吗?
注意: 经过深入研究:这个 stackoverflow 答案深入阐述了 @ModelAttribute: @ModelAttribute 注释,何时使用它?
我从我的托管公司那里收到了三个文件,他们为我购买了 X.509 证书。
.key文件 - 那是私钥
.cert文件 - ?
.cacert文件 - ?
两者有什么区别?
Angular 项目中是否可能只有一个(!)自定义纯管道实例?
在我看来,Angular 正在为项目中的每个不同组件创建一个自定义管道的新实例。它为我使用管道的每个不同组件调用管道的构造函数。
它与缓存能力有关。我希望在我的不同组件中使用模板中的一个管道,只有我的自定义纯管道的一个实例!
假设我在 Spring 中有一个使用 Kotlin 的控制器方法,并且我想返回 aResponseEntity<Test>或ResponseEntity<Error>。
我怎样才能在 Kotlin 中实现这个功能?我尝试过使用ResponseEntitiy<Any>orResponseEntity<*>但 Kotlin 总是抱怨。
那么如何让返回类型真正通用呢?
@GetMapping
fun test(): Mono<ResponseEntity<?????>>
{
return Mono.just(1)
.map { ResponseEntity.ok(Test("OK") }
.switchIfEmpty(Mono.just(ResponseEntity.badRequest().body(Error("Error"))))
}
Run Code Online (Sandbox Code Playgroud) spring ×3
java ×2
kotlin ×2
spring-boot ×2
angular ×1
annotations ×1
class ×1
cors ×1
data-binding ×1
exception ×1
hibernate ×1
html ×1
inline ×1
jackson ×1
javascript ×1
jpa ×1
lazy-loading ×1
pipe ×1
spring-data ×1
spring-mvc ×1
ssl ×1
unit-testing ×1
webrtc ×1