在Spring Boot中,可以在application.properties文件中定义应用程序属性.例如,Rest的前缀可以定义为
spring.data.rest.basePath=api
Run Code Online (Sandbox Code Playgroud)
对于基于Spring Boot的JHipster,我想应用程序属性可以在application.yml文件中定义.但是以下方法都不适用于我:404错误.
spring.data.rest.basePath: api
spring:
data:
rest:
basePath: api
Run Code Online (Sandbox Code Playgroud)
另一种可能性是配置本身不起作用.
Scala 中的枚举数据类型是否可以实现为 String as
enum Currency {CAD, EUR, USD }
Run Code Online (Sandbox Code Playgroud)
在 Java 中而不是
object Currency extends Enumeration {
val CAD, EUR, USD = Value
}
Run Code Online (Sandbox Code Playgroud)
哪个数据值是二进制的?
我在 Java 和 Scala 中编写了相同的功能。枚举数据保存到数据库中。Java 版本适用于 String 值,但不适用于二进制数据的 Scala 版本。
我想针对日期搜索编写一个测试。我正在考虑类似的测试代码
assertThat(repository.findByBookingDateAfter(LocalDate.of(2016, 1, 1))).extracting("bookingDate").are(...));
Run Code Online (Sandbox Code Playgroud)
其中类结构如下所示:
public class Booking{
...
LocalDate bookingDate;
...
}
Run Code Online (Sandbox Code Playgroud)
因为查询是针对给定日期之后的任何预订,所以我的测试将检查该字段确实晚于该日期。经过一番网上搜索,我没有看到任何有用的信息。我想知道我是否走在正确的道路上。
有什么建议么?
更新:
后来,我在 build.gradle 文件中更改了依赖项设置,如下所示:
testCompile('org.springframework.boot:spring-boot-starter-test'){
exclude group: 'org.assertj'
}
testCompile group: 'org.assertj', name: 'assertj-core', version: '3.6.2'
Run Code Online (Sandbox Code Playgroud)
拥有最新版本的assertj。
更新2:
以下是所有以“is”开头的方法的屏幕截图。“isAfter”不在列表中。
在我运行以下 kubectl 命令之后
kubectl create deployment springdeployment --image=docker.io/me/sample-app:latest -o yaml --dry-run=client > sample-app.yaml
Run Code Online (Sandbox Code Playgroud)
我收到一个错误:
Error: invalid argument "client" for "--dry-run" flag: strconv.ParseBool: parsing "client": invalid syntax
Run Code Online (Sandbox Code Playgroud)
尽管根据 kubectl 文档,“client”是“--dry-run”的三个参数选项之一。
我的 kubectl 版本是
Client Version: version.Info{Major:"1", Minor:"14+", GitVersion:"v1.14.10-dispatcher", GitCommit:"f5757a1dee5a89cc5e29cd7159076648bf21a02b", GitTreeState:"clean", BuildDate:"2020-02-12"
Run Code Online (Sandbox Code Playgroud)
根据在线数据,其他人也遇到了此错误。但是,我还没有看到解决方案。
如何解决这个问题?
我正在使用Spring Data Rest MongoDB为我的应用程序编写单元测试.基于Josh的"使用Spring构建REST服务"获取入门指南,我有以下测试代码:
@Test
public void readSingleAccount() throws Exception {
mockMvc.perform(get("/accounts/"
+ this.account.getId()))
.andExpect(status().isOk())
.andExpect(content().contentType(contentType))
.andExpect(jsonPath("$.id", is(this.account.getId())))
.andExpect(jsonPath("$.email", is(this.account.getEmail())))
.andExpect(jsonPath("$.password", is(this.account.getPassword())));
}
Run Code Online (Sandbox Code Playgroud)
此测试在内容类型上失败.
Content type expected:<application/json;charset=UTF-8> but was: <application/hal+json>
Expected :application/json;charset=UTF-8
Actual :application/hal+json
Run Code Online (Sandbox Code Playgroud)
我没有看到MediaType带有HAL.内容类型是否在另一个类中定义?
在Spring Security中,什么时候添加"ROLE_"前缀合适?在使用的示例中@PreAuthorize("hasRole('ROLE_USER')"),确实如此。但是在此示例中,它没有:
http
.httpBasic()
.and()
.authorizeRequests()
.antMatchers(HttpMethod.POST, "/books").hasRole("ADMIN")
Run Code Online (Sandbox Code Playgroud)
接下来呢?
SecurityContext securityContext = new SecurityContextImpl();
final Properties users = new Properties();
users.put("joe","secret,ADMIN,enabled"); <-- here
InMemoryUserDetailsManager manager = new InMemoryUserDetailsManager(users);
Run Code Online (Sandbox Code Playgroud)
和
Collection<GrantedAuthority> grantedAuthorities = new ArrayList<GrantedAuthority>();
grantedAuthorities.add(new SimpleGrantedAuthority("ROLE_ADMIN")); <-- here
AnonymousAuthenticationToken anonymousAuthenticationToken = new AnonymousAuthenticationToken("test", manager.loadUserByUsername("joe"), grantedAuthorities);
securityContext.setAuthentication(anonymousAuthenticationToken);
SecurityContextHolder.setContext(securityContext);
Run Code Online (Sandbox Code Playgroud)
是否有使用的特定规则?
在对 MongoDB 地理数据查询进行单元测试期间,我收到以下错误消息:
找不到任何特殊索引:2d(需要索引),2dsphere(需要索引),对于:{ address.location: { $nearSphere: { x: -120.0, y: 47.0 }, $maxDistance: 0.01567855942887398 }, status: “在里面” }; 嵌套异常是 com.mongodb.MongoException: can't find any special index: 2d (needs index), 2dsphere (needs index), for: { address.location: { $nearSphere: { x: -120.0, y: 47.0 } , $maxDistance: 0.01567855942887398 }, 状态: "INIT" }
createIndex但是,运行该命令后,我收到以下错误:
db.store.createIndex({"address.location":"2d"}) 预期位置对象,位置数组格式不正确 db.store.createIndex({"address.location":"2dsphere"}) 无法提取来自对象的地理键,畸形几何?:{类型:“点”,坐标:[47.399465,-122.2950165]}
文档数据的结构如下:
{
....
"address" : {
"street" : "Street One",
"city" : "One City",
"province" : "aProvince",
"country" : "aCountry",
"postalCode" : "91202",
"location" …Run Code Online (Sandbox Code Playgroud) 虽然我知道AngularJS,但我想将Vue用于我的下一个JHipster项目,因为它比AngularJS和Angular 2更简单.我没有从Vue模块中获得太多.我想将生成的AngularJS转换为Vue更容易,而不是从头开始.有关此主题的任何建议或意见?
我认为 Java 14 中新的 Java Record 数据类型应该适用于跨网络的数据,因为数据不应该在过程中发生变化,这是记录数据类型的主要特征 - 不可变。
我使用 RSocket 中的数据类型。在发送方,编码器出现错误。我还没有找到编码器是关于什么的。在接收器端,出现解串器错误。据我所知,记录不能实现诸如 Serializable 之类的接口。
所以,记录数据类型不适用于网络编程,对吗?
更新:
我将 Serializable 接口添加到发送方和接收方的记录定义中。发出请求后,TCP发送端没问题,但接收端报错
No encoder for com.....data.Notification, current value type is class com.....data.Notification
Run Code Online (Sandbox Code Playgroud)
那些标记这个问题的人有不同的经历吗?