我的一个控制器中有以下代码:
@Controller
@RequestMapping("/preference")
public class PreferenceController {
@RequestMapping(method = RequestMethod.GET, produces = "text/html")
public String preference() {
return "preference";
}
}
Run Code Online (Sandbox Code Playgroud)
我只是尝试使用Spring MVC测试来测试它,如下所示:
@ContextConfiguration
@WebAppConfiguration
@RunWith(SpringJUnit4ClassRunner.class)
public class PreferenceControllerTest {
@Autowired
private WebApplicationContext ctx;
private MockMvc mockMvc;
@Before
public void setup() {
mockMvc = webAppContextSetup(ctx).build();
}
@Test
public void circularViewPathIssue() throws Exception {
mockMvc.perform(get("/preference"))
.andDo(print());
}
}
Run Code Online (Sandbox Code Playgroud)
我收到以下异常:
循环视图路径[preference]:将再次调度回当前处理程序URL [/ preference].检查您的ViewResolver设置!(提示:由于默认的视图名称生成,这可能是未指定视图的结果.)
我发现奇怪的是,当我加载包含模板和视图解析器的"完整"上下文配置时,它工作正常,如下所示:
<bean class="org.thymeleaf.templateresolver.ServletContextTemplateResolver" id="webTemplateResolver">
<property name="prefix" value="WEB-INF/web-templates/" />
<property name="suffix" value=".html" …
Run Code Online (Sandbox Code Playgroud) spring spring-mvc circular-reference thymeleaf spring-mvc-test
我有以下测试类:
@ActiveProfiles({ "DataTC", "test" })
@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration(classes = {BaseTestConfiguration.class, DataTestConfiguration.class, JpaConfiguration.class, PropertyPlaceholderConfiguration.class })
public class RegularDayToTimeSlotsTest {
...
Run Code Online (Sandbox Code Playgroud)
问题似乎来自BaseTestConfiguration类:
@Configuration
@ComponentScan(basePackages = { "com.bignibou" }, excludeFilters = { @Filter(type = FilterType.CUSTOM, value = RooRegexFilter.class),
@Filter(type = FilterType.ANNOTATION, value = Controller.class), @Filter(type = FilterType.ANNOTATION, value = ControllerAdvice.class) })
public class BaseTestConfiguration {
}
Run Code Online (Sandbox Code Playgroud)
我系统地得到这个例外:
Caused by: java.lang.IllegalArgumentException: A ServletContext is required to configure default servlet handling
at org.springframework.util.Assert.notNull(Assert.java:112)
at org.springframework.web.servlet.config.annotation.DefaultServletHandlerConfigurer.<init>(DefaultServletHandlerConfigurer.java:54)
at org.springframework.web.servlet.config.annotation.WebMvcConfigurationSupport.defaultServletHandlerMapping(WebMvcConfigurationSupport.java:329)
at org.springframework.web.servlet.config.annotation.DelegatingWebMvcConfiguration$$EnhancerByCGLIB$$bb4ceb44.CGLIB$defaultServletHandlerMapping$22(<generated>)
at org.springframework.web.servlet.config.annotation.DelegatingWebMvcConfiguration$$EnhancerByCGLIB$$bb4ceb44$$FastClassByCGLIB$$368bb5c1.invoke(<generated>)
at org.springframework.cglib.proxy.MethodProxy.invokeSuper(MethodProxy.java:228)
at org.springframework.context.annotation.ConfigurationClassEnhancer$BeanMethodInterceptor.intercept(ConfigurationClassEnhancer.java:326)
at …
Run Code Online (Sandbox Code Playgroud) @NoRepositoryBean
在阅读Spring Data文档时,我多次遇到界面.
引用文档:
如果您正在使用Spring命名空间使用Spring命名空间进行自动存储库接口检测,那将导致Spring尝试创建MyRepository实例.这当然不是所希望的,因为它只是在Repository和您要为每个实体定义的实际存储库接口之间起中间作用.要将扩展存储库的接口排除在实例化为存储库实例之外,请使用
@NoRepositoryBean
.
但是,我仍然不确定何时何地使用它.有人可以建议并给我一个具体的用法示例吗?
我不确定将Unit指定为我的scala方法的返回类型或完全省略返回类型之间的区别.有什么不同?
任何人都可以建议吗?
我参考了路由器商店的ngrx项目(https://github.com/ngrx/router-store).
我不清楚如何使用这个项目......
例如,让我们从项目文档中获取以下示例:
store.dispatch(go(['/path', { routeParam: 1 }], { query: 'string' }));
Run Code Online (Sandbox Code Playgroud)
这是否意味着用作角2路由器的替代品:router.navigate(['/path...
?
...或者我应该仅在某些情况下使用ngrx路由器存储?(如果是那些?)
当<a routerLink="/heroes"
点击角度2路由器html链接时,ngrx路由器存储会发生什么 ?
更一般地说,与使用普通的角度2路由器相比,有人可以解释一下ngrx路由器商店项目所取得的成果吗?
或者换句话说,除了角度2路由器之外,ngrx路由器商店还带来了什么?
编辑:关于ngrx的有趣的信息和样本来源当然是ngrx example-app(https://github.com/ngrx/example-app).
我发现了对路由器存储的依赖,但我无法找到应用程序中路由器存储的使用位置...
仅供参考,这里是关于路由器商店的示例应用程序中的注释:
@ ngrx/router-store使路由器状态在商店中保持最新,并将商店用作路由器状态的唯一真实来源.
我试图将Spring依赖注入到JPA EntityListener中.这是我的听众课程:
@Configurable(autowire = Autowire.BY_TYPE, dependencyCheck = true)
public class PliListener {
@Autowired
private EvenementPliRepository evenementPliRepository;
@PostPersist
void onPostPersist(Pli pli) {
EvenementPli ev = new EvenementPli();
ev.setPli(pli);
ev.setDateCreation(new Date());
ev.setType(TypeEvenement.creation);
ev.setMessage("Création d'un pli");
System.out.println("evenementPliRepository: " + evenementPliRepository);
evenementPliRepository.save(ev);
}
}
Run Code Online (Sandbox Code Playgroud)
这是我的Entity类:
@RooJavaBean
@RooToString
@RooJpaActiveRecord
@EntityListeners(PliListener.class)
public class Pli implements Serializable{
...
Run Code Online (Sandbox Code Playgroud)
但是,我的依赖(即evenementPliRepository
)始终为null.
有人可以帮忙吗?
我一直在使用Tomcat很长一段时间,但我不确定是什么
目录用于和我需要清理哪些.
任何人都可以建议吗?
我开发了一个MemberRepository
扩展的Spring Data存储库接口org.springframework.data.jpa.repository.JpaRepository
.MemberRepository
有一个方法:
@Cacheable(CacheConfiguration.DATABASE_CACHE_NAME)
Member findByEmail(String email);
Run Code Online (Sandbox Code Playgroud)
结果由Spring缓存抽象缓存(由a支持ConcurrentMapCache
).
我的问题是,我想要写一个集成测试(针对HSQLDB)断言结果被从数据库第一次检索,并从缓存中的第二次.
我最初想过嘲笑jpa基础设施(实体经理等),并以某种方式断言实体经理第二次没有被调用但看起来太难/笨重(参见/sf/answers/1640972021/).
那么有人可以提供有关如何测试带有注释的Spring Data Repository方法的缓存行为的建议@Cacheable
吗?
我希望能够从Service spring bean 动态检索我的spring Web应用程序的" servlet上下文路径 "(例如http://localhost/myapp
或http://www.mysite.com
).
这样做的原因是我想在将要发送给网站用户的电子邮件中使用此值.
虽然从Spring MVC控制器执行此操作非常容易,但从Service bean执行此操作并不是那么明显.
任何人都可以建议吗?
编辑:附加要求:
我想知道是否有一种方法可以在启动应用程序时检索上下文路径,并且可以通过我的所有服务随时检索它?
由于切换到Angular 2的最新版本(即在github,master上),我收到有关我所有组件的警告:
NgModule DynamicModule通过"entryComponents"使用HomeComponent,但既未声明也未导入!最终结束后,此警告将成为错误.
除了以外,我得到了所有组件的相同错误消息HomeComponent
.
有人可以提供有关这些的信息吗?
spring ×6
jpa ×2
spring-data ×2
spring-mvc ×2
angular ×1
contextpath ×1
directory ×1
java ×1
ngrx ×1
return-type ×1
scala ×1
servlets ×1
spring-cache ×1
spring-roo ×1
spring-test ×1
temp ×1
testing ×1
thymeleaf ×1
tomcat ×1
void ×1