我@Query在存储库中有一个自定义,如下所示:
SELECT * FROM topicaudit_c14001
WHERE auditdate >= NOW()
AND auditdate <= NOW() + '1 hour'::INTERVAL
AND accepted_status = 'ACCEPTED'
AND reminder_sent = FALSE
Run Code Online (Sandbox Code Playgroud)
当我运行这个时,我得到异常:
org.hibernate.QueryException:
Not all named parameters have been set: [:INTERVAL]
Run Code Online (Sandbox Code Playgroud)
显然,它将::INTERVAL转换(Postgresql)解释为命名参数,并且无法触发查询,因为我没有提供参数。
我怎样才能编写这个查询以便它可以与 JPA 一起使用?
我正在尝试将实例列表注入到我的 Angular 组件中,但由于它不起作用并且我找不到任何相关文档,我认为这可能是不可能的。因此,在这种情况下,我的问题是如何以干净的方式实现相同的效果,而无需手动连接任何东西。
例如,在 Spring 中,我将有一些从抽象Action类扩展或实现Action接口的具体操作。
@Component
class MyAction1 extends Action {
...
}
@Component
class MyAction2 extends Action {
...
}
@Component
class MyConsumer {
@Autowired
List<Action> actions;
}
Run Code Online (Sandbox Code Playgroud)
由于MyAction1和MyAction2是在运行时加载的,MyConsumer因此其列表将填充 2 个实例。有什么方法可以在 Angular 中做到这一点而无需手动连接吗?
编辑: 在角度代码中我想要的是:
export abstract class ActionBase {
...
}
@Injectable()
export class MyAction1 extends ActionBase {
...
}
@Injectable()
export class MyAction2 extends ActionBase {
...
}
@Component(...)
export class MyConsumerComponent {
constructor( …Run Code Online (Sandbox Code Playgroud) 我想ObjectMapper在我的项目中使用 Jackson 的配置版本(忽略空值和 snake_case,也使用一些自定义模块)。
在我的大型项目中,我无法让 Spring MVC 实际使用这个映射器。
build.gradle:
buildscript {
ext {
springBootVersion = '1.5.6.RELEASE'
}
repositories {
mavenCentral()
}
dependencies {
classpath("org.springframework.boot:spring-boot-gradle-plugin:${springBootVersion}")
}
}
apply plugin: 'java'
apply plugin: 'idea'
apply plugin: 'org.springframework.boot'
version = '0.0.1-SNAPSHOT'
sourceCompatibility = 1.8
repositories {
mavenCentral()
}
dependencies {
compile('org.springframework.boot:spring-boot-starter')
compile("org.springframework.boot:spring-boot-starter-jetty:${springBootVersion}")
compile("org.springframework.boot:spring-boot-starter-web:${springBootVersion}")
compile group: 'com.fasterxml.jackson.core', name: 'jackson-core', version: '2.8.8'
compile group: 'com.fasterxml.jackson.core', name: 'jackson-databind', version: '2.8.8'
testCompile('org.springframework.boot:spring-boot-starter-test')
}
Run Code Online (Sandbox Code Playgroud)
我的应用程序.yml:
spring:
application:
name: Jackson test
jackson:
property-naming-strategy: SNAKE_CASE
default-property-inclusion: non_empty
debug: …Run Code Online (Sandbox Code Playgroud) 我使用Mockito和Spring 4进行了单元测试设置.我的测试看起来像这样:
@ContextConfiguration(classes = {
MyTestConfig.class,
SecurityConfig.class,
OAuth2Config.class
})
@RunWith(MockitoJUnitRunner.class)
public class ControllerAccessTests {
private MockMvc mockMvc;
@Autowired
private FilterChainProxy springSecurityFilterChain;
@Mock
private CreditCardPaymentService creditCardPaymentService;
@InjectMocks
private CreditCardRestController creditCardRestController;
@Before
public void setUp() throws Exception {
mockMvc = MockMvcBuilders
.standaloneSetup(creditCardRestController)
.apply(springSecurity(springSecurityFilterChain))
.build();
when(creditCardPaymentService.doPreAuthPayment(any())).thenReturn(null);
}
@Test
//.... some unit tests
Run Code Online (Sandbox Code Playgroud)
使用如下所示的配置文件:
@Configuration
public class MyTestConfig {
@Bean
public FilterChainProxy springSecurityFilterChain(){
AntPathRequestMatcher matcher = new AntPathRequestMatcher("/**");
DefaultSecurityFilterChain chain = new DefaultSecurityFilterChain(matcher);
return new FilterChainProxy(chain);
}
}
Run Code Online (Sandbox Code Playgroud)
当我启动单元测试springSecurityFilterChain为空时,似乎配置文件MyTestConfig似乎没有加载.有任何想法吗?
干杯汤姆
spring ×2
spring-mvc ×2
angular ×1
casting ×1
hibernate ×1
jackson ×1
java ×1
jpa ×1
mockito ×1
postgresql ×1
spring-boot ×1
typescript ×1
unit-testing ×1