Found interface org.springframework.test.context.TestContext, but class was expected弹簧核心从3.2迁移到4后,我开始变得异常.我正在使用mvn clean testjava 7作为maven编译器版本.
任何想法如何处理?
在标题中 - 我的@RestResource(exported = false)在字段上被忽略.Spring数据休息仍然想从中创建json,我想暂时跳过它,因为在WorkflowEvent中更改rel没有给我任何东西..
@OneToMany(cascade = CascadeType.ALL, fetch = FetchType.LAZY, mappedBy = "submission")
@OrderBy("date desc")
@RestResource(exported = false)
private List<WorkflowEvent> events = new ArrayList<WorkflowEvent>();
Run Code Online (Sandbox Code Playgroud)
我明白了:
{"timestamp":1410850806347,"status":500,"error":"Internal Server Error","exception":"org.springframework.http.converter.HttpMessageNotWritableException","message":"Could not write JSON: Detected multiple association links with same relation type! Disambiguate association @javax.persistence.JoinColumn(insertable=true, unique=false, referencedColumnName=, columnDefinition=, name=submission_id, updatable=true, nullable=true, table=, foreignKey=@javax.persistence.ForeignKey(name=, value=CONSTRAINT, foreignKeyDefinition=)) @javax.persistence.ManyToOne(fetch=EAGER, cascade=[], optional=true, targetEntity=void) @org.springframework.data.rest.core.annotation.RestResource(description=@org.springframework.data.rest.core.annotation.Description(value=), path=, exported=false, rel=) private mypackage.MyClass mypackage.WorkflowEvent.myclass using @RestResource!; nested exception is com.fasterxml.jackson.databind.JsonMappingException: Detected multiple association links with same relation*
Run Code Online (Sandbox Code Playgroud)
当我评论这个领域时它是有效的.
我的版本:
\- …Run Code Online (Sandbox Code Playgroud) 是否有任何方便的方法来获取在onError处理程序中引起任何异常的对象?
我想做类似的事情:
observable.subscribe(
unit -> {
//something can throw ex here..
},
error->logger.error("error on {}", unit, error));
Run Code Online (Sandbox Code Playgroud) 所以,我在我的项目中使用spring session.如何使用它在项目中编写集成测试?我应该为春季会议内部模拟一些东西吗?或者使用嵌入式redis的任何合理方式?
我看到过去有一些@EnableEmbeddedRedis注释,但似乎已被删除:https://github.com/spring-projects/spring-session/issues/248
//编辑
我试过通过MockHttpSession
mockMvc.perform(post("/register").session(mockHttpSession)
Run Code Online (Sandbox Code Playgroud)
但春天尝试并且无论如何都无法连接到redis.
我试图为stockfigher游戏api写包装器,只是为了学习伪装的工作原理,而我对第一个POST方法有疑问:
@RequestMapping(method = RequestMethod.POST, value = "/venues/KHEX/stocks/LMC/orders")
void newOrderForAStock(String order);
Run Code Online (Sandbox Code Playgroud)
每当我尝试调用它时,都会出现异常:
Caused by: feign.RetryableException: cannot retry due to redirection, in streaming mode executing POST https://api.stockfighter.io/ob/api//venues/KHEX/stocks/LMC/orders
at feign.FeignException.errorExecuting(FeignException.java:56)
at feign.SynchronousMethodHandler.executeAndDecode(SynchronousMethodHandler.java:97)
at feign.SynchronousMethodHandler.invoke(SynchronousMethodHandler.java:71)
at feign.ReflectiveFeign$FeignInvocationHandler.invoke(ReflectiveFeign.java:94)
at com.sun.proxy.$Proxy50.newOrderForAStock(Unknown Source)
at karolik.michal.stockfighter.runner.TestIt.buyFirst(TestIt.java:45)
at karolik.michal.stockfighter.runner.TestIt.runIt(TestIt.java:32)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:497)
at org.springframework.beans.factory.annotation.InitDestroyAnnotationBeanPostProcessor$LifecycleElement.invoke(InitDestroyAnnotationBeanPostProcessor.java:349)
at org.springframework.beans.factory.annotation.InitDestroyAnnotationBeanPostProcessor$LifecycleMetadata.invokeInitMethods(InitDestroyAnnotationBeanPostProcessor.java:300)
at org.springframework.beans.factory.annotation.InitDestroyAnnotationBeanPostProcessor.postProcessBeforeInitialization(InitDestroyAnnotationBeanPostProcessor.java:133)
... 22 common frames omitted
Run Code Online (Sandbox Code Playgroud)
有什么办法可以调整吗?
所以,
我正在使用 RestTemplate 访问某个页面,这将需要重定向(重定向到 oauth 2 提供程序,但这可能无关紧要)。
我正在做:
ResponseEntity<String> forEntity = oAuth2RestTemplate.getForEntity(url, String.class, Collections.emptyMap());
Run Code Online (Sandbox Code Playgroud)
使用标准OAuth2RestTemplate,我还没有对这个 bean 进行任何自定义创建,所以它只是从 spring 注入的。
作为响应,我得到ResponseEntity了location标头和 302 状态,但没有遵循。从许多其他来源判断,如果我所做的只是GET- 类似的问题:Follow 302 redirect using Spring restTemplate?
这不是一个案例,没有重定向发生,我错过了什么吗?我是否必须手动抓取它location 并手动重定向到它?
更新:
好的,作为它的 OAuth2RestTemplate,它使用 OAuth2AccessTokenSupport 作为请求工厂。此类将工厂配置为不遵循重定向。可惜太难找了。
但是使用也= new RestTemplate()无济于事(注意 new 关键字,如果您要自动装配它,那么 spring 将自动装配 oauth2RestTemplate )。
我正在将 spring 会话与 redis 一起使用,但我想在进行测试时禁用它。我的班级有注释:
@ActiveProfiles("integrationtests")
Run Code Online (Sandbox Code Playgroud)
我的 application-integrationtests.tml 文件包含:
spring.autoconfigure.exclude: org.springframework.boot.autoconfigure.data.redis.RedisAutoConfiguration
Run Code Online (Sandbox Code Playgroud)
但它仍然失败:
Caused by: org.springframework.data.redis.RedisConnectionFailureException: Cannot get Jedis connection; nested exception is redis.clients.jedis.exceptions.JedisConnectionException: Could not get a resource from the pool
Run Code Online (Sandbox Code Playgroud)
如果我打开 redis-server ,测试就会工作,但我当然不想保持这种状态;)
//更新
我一直在尝试
@SpringBootTest(classes = {Application.class})
@ActiveProfiles("integrationtests")
Run Code Online (Sandbox Code Playgroud)
和排除 Redis 的 Application.class:
@SpringBootApplication(exclude={SessionAutoConfiguration.class, RedisAutoConfiguration.class, RedisHttpSessionConfiguration.class})
public class Application {
public static void main(String[] args) throws Exception {
SpringApplication.run(Application.class, args);
}
}
Run Code Online (Sandbox Code Playgroud)
但它失败了:
Error creating bean with name 'redisMessageListenerContainer' defined in class path resource [org/springframework/session/data/redis/config/annotation/web/http/RedisHttpSessionConfiguration.class]
Run Code Online (Sandbox Code Playgroud)
spring autoconfigure debug看到我已经排除了这个类,但是没有效果: …
就像在主题中一样-是否有任何方法可以验证当前版本是否是使用“重播”按钮的效果?
所以,我有一个带有@Builder注释和自定义setter的类,除了设置this.authorities之外,还有其他功能
@Setter(AccessLevel.NONE)
private Collection<Authority> authorities;
public void setAuthorities(Collection<Authority> authorities...
Run Code Online (Sandbox Code Playgroud)
但是在使用类构建器时会忽略此setter.
对我来说另一件奇怪的事情是,authorities即使我删除了我的二传手,构建器仍然有方法.这是一个错误还是我在这里做错了什么?
我们使用 gopkg.in/mgo.v2/bson 与 mongo 对话,它的 API 填充传递的结构而不是返回结果,例如:
func (p *Pipe) One(result interface{}) error {...
Run Code Online (Sandbox Code Playgroud)
当我想模拟/测试使用它的代码时,就会出现问题。我想模拟这个执行并以某种方式获得“结果”中的填充值。目前测试有:
query.EXPECT().One(gomock.Any())
Run Code Online (Sandbox Code Playgroud)
正如您所看到的,我没有获得任何值,我只是配置 gomock 来检查当我运行我的方法时是否必须调用 query.One 。我无法通过这样的结构
mystruct := MyStruct{}
query.EXPECT().One(&mystruct)
Run Code Online (Sandbox Code Playgroud)
因为测试代码中的 mystruct 和实际代码中的 mystruct 不同,验证模拟将失败(引用不同)。我正在寻找类似于mockito的参数捕获器的东西: https ://static.javadoc.io/org.mockito/mockito-core/2.6.9/org/mockito/ArgumentCaptor.html
我们在同一个域后面有两个项目(前面有 zuul proxy ),两个项目都使用 spring 会话项目,会话保存在 redis 中。
这两个会话应该是不同的,但似乎它们正在覆盖名为“SESSION”的 cookie 中的彼此 ID。如何更改该名称?有没有什么简单的方法可以通过配置来做到这一点?
我试图用scalatest测试PersistentActor,但我不知道如何指向测试代码使用application-test.conf之类的东西而不是application.conf(我想将事件的leveldb存储改为内存存储).有没有方便的方法呢?
我有一个枚举:
public enum Roles {
USER,ADMIN;
}
Run Code Online (Sandbox Code Playgroud)
我的表单上有一个CheckBoxGroup:
private CheckBoxGroup<String> rolesCheckbox = new CheckBoxGroup<>("User roles");
Run Code Online (Sandbox Code Playgroud)
绑定到此表单的User类的实例有一个字段:
private List<Roles> roles;
Run Code Online (Sandbox Code Playgroud)
而我现在要做的就是在打开特定用户实例的表单时检查正确的复选框.我可能必须做一些insinde binder.forField,但我真的不知道如何:
binder.forField(rolesCheckbox).bind(...
Run Code Online (Sandbox Code Playgroud)