Skip to content

Commit 45711bb

Browse files
UbuntuUbuntu
Ubuntu
authored and
Ubuntu
committed
Add QuerydslWebFluxConfiguration
1 parent 5c343b5 commit 45711bb

File tree

1 file changed

+78
-0
lines changed

1 file changed

+78
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
/*
2+
* Copyright 2015-2021 the original author or authors.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* https://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
package org.springframework.data.webflux.config;
17+
18+
import java.util.Optional;
19+
20+
import org.springframework.beans.factory.BeanFactory;
21+
import org.springframework.beans.factory.ObjectFactory;
22+
import org.springframework.beans.factory.ObjectProvider;
23+
import org.springframework.beans.factory.annotation.Autowired;
24+
import org.springframework.beans.factory.annotation.Qualifier;
25+
import org.springframework.context.annotation.Bean;
26+
import org.springframework.context.annotation.Configuration;
27+
import org.springframework.context.annotation.Lazy;
28+
import org.springframework.core.convert.ConversionService;
29+
import org.springframework.data.querydsl.EntityPathResolver;
30+
import org.springframework.data.querydsl.SimpleEntityPathResolver;
31+
import org.springframework.data.querydsl.binding.QuerydslBindingsFactory;
32+
import org.springframework.data.webflux.querydsl.QuerydslPredicateArgumentResolver;
33+
import org.springframework.web.reactive.config.WebFluxConfigurer;
34+
import org.springframework.web.reactive.result.method.annotation.ArgumentResolverConfigurer;
35+
36+
/**
37+
* Querydsl-specific web configuration for Spring Data. Registers a {@link HandlerMethodArgumentResolver} that builds up
38+
* {@link Predicate}s from web requests.
39+
*
40+
* @author Oliver Gierke
41+
* @author Mark Paluch
42+
* @author Matías Hermosilla
43+
* @since 1.11
44+
* @soundtrack Anika Nilles - Alter Ego
45+
*/
46+
@Configuration(proxyBeanMethods = false)
47+
public class QuerydslWebFluxConfiguration implements WebFluxConfigurer {
48+
49+
@Autowired @Qualifier("webFluxConversionService") ObjectFactory<ConversionService> conversionService;
50+
@Autowired ObjectProvider<EntityPathResolver> resolver;
51+
@Autowired BeanFactory beanFactory;
52+
53+
/**
54+
* Default {@link QuerydslPredicateArgumentResolver} to create Querydsl {@link Predicate} instances for Spring MVC
55+
* controller methods.
56+
*
57+
* @return
58+
*/
59+
@Lazy
60+
@Bean
61+
public QuerydslPredicateArgumentResolver querydslPredicateArgumentResolver() {
62+
return new QuerydslPredicateArgumentResolver(
63+
beanFactory.getBean("querydslBindingsFactory", QuerydslBindingsFactory.class),
64+
Optional.of(conversionService.getObject()));
65+
}
66+
67+
@Lazy
68+
@Bean
69+
public QuerydslBindingsFactory querydslBindingsFactory() {
70+
return new QuerydslBindingsFactory(resolver.getIfUnique(() -> SimpleEntityPathResolver.INSTANCE));
71+
}
72+
73+
@Override
74+
public void configureArgumentResolvers(ArgumentResolverConfigurer configurer) {
75+
configurer.addCustomResolver(beanFactory.getBean("querydslPredicateArgumentResolver", QuerydslPredicateArgumentResolver.class));
76+
}
77+
78+
}

0 commit comments

Comments
 (0)