Comments (3)
So we have an enablement config with map of PV services to downloader names, but how to validate this map
Q: can we put custom ConstrainValidator
into spring ApplicationContext
and let it has depending bean of Preference
?
A: Yes, a ConstrainValidator
can be a spring component with other dependent components
Q2: can the custom validator contains a bean of Environment
and call checkProperty()
method to validate if a property root path exist?
A: Yes and No, we can only check if the full name property exists, but not the root
from vocadb-video-downloader-new.
About solution for loading only enabled downloaders:
- use
@Conditional(MyCondition.class)
.- Try either annotate
MyCondition
with@Component
or using theBeanFactory
inConditionContext
from the implemented method - An: since
Condition
initialized at the very first stage of the Spring life cycle, we can't use any beans. In fact, we will get a nullBeanFactory
fromConditionContext
. The only thing we can do is useEnvironment
fromConditionContext
to check some properties
- Try either annotate
-
let all downloader configs have two common properties,this works if only onenable
andorder
. and let all downloaders@ConditionalOnProperty
on theirenable
propertyenable
property, but how to disable the downloader ifpv-preference
doesn't include the target PV service, see #11validation on downloader config will be fully working as the user may disable the downloaderyou can put@Validated
on downloader class itself and put@field:Valid
on the holding config bean
- Spring Lazy Initialization. Since all downloaders are getten through
BeanFactory
only, we could try Lazy Initialization- can
@ConfigurationProperties
with@Validated
been lazily validated and initialized? - An: Yes, but must enable global lazy initialization by
spring.main.lazy-initialization=true
. Otherwise@ConfigurationProperties
always initialized at startup even if it is@Lazy
.@Bean
s and@Component
s can be lazily loaded. - If don't want
spring.main.lazy-initialization=true
, we can use next option
- can
- call
Validator.validate()
. e.g. insidelazy {}
orinit {}
block- is an easy understand solution, but
Validator
bean will be passed to various business codes. Make things look uglier
- is an easy understand solution, but
from vocadb-video-downloader-new.
FInal answer: use @Conditonal(MyCondition.class)
Reason:
- eager initialization is still needed so that no config validation failure during the business logic part (remember that
RecordListener
listens to all exception) - good isolation of validation code and business code, although this method led to more code to write
- very very very, fortunately, all our condition is based on configuration properties, so the limitation of using
@Conditonal(MyCondition.class)
doesn't affect our project.- but this might not be the case in future projects, consider using Micronauts framework or
POC creating our own auto-configuration classes(this is for writing libraries)
- but this might not be the case in future projects, consider using Micronauts framework or
from vocadb-video-downloader-new.
Related Issues (20)
- How to handle error path with easy-batch HOT 1
- features about downloading pvs
- retry mechanism in downloader HOT 1
- Try to complete it before the final release of 2022年V家新曲合集 HOT 2
- add thin jar config HOT 1
- how to load user command line from YAML
- Improve how PV Type is handled in pvTaskDecider
- A even better downloader enablement mechanism HOT 2
- Solve conflict on file naming HOT 1
- Try finish the project refactoring before the end of 2022
- Use docker to setup test&production env HOT 1
- Remove easy-batch, but observe the batch pattern HOT 1
- Add MP3 tagging support in extractor module HOT 1
- use aggregated parameter object HOT 3
- Dependency Dashboard
- Add sort order support for so-ID and sm-ID
- Create a new project for openapi-vocadb-java-client-autofixer
- Deprecate vocadb-openapi-client-java in favour of vocadb-openapi-dto-java HOT 2
- A way better sorting and enablement for PVs HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from vocadb-video-downloader-new.