spring-data


How to set arrays of string to #EnableJpaRepositories from property files


I have a jpa configuration file with #EnableJpaRepositories annotaion. I set this annotaion value from application.properties file like this :
#EnableJpaRepositories("${jpa.repository.packages}")
public class JPAConfiguration {
....
}
and here is my application.properties file:
jpa.repository.packages=com.epms.model
and it works perfect. but i want to specify multiple packages for #EnableJpaRepositories . so i changed my config file to this :
jpa.repository.packages=com.epms.model,com.ecms.model
and also configuration file to this :
#EnableJpaRepositories("#{'${jpa.repository.packages}'.split(',')}")
public class JPAConfiguration {
}
but it's not working . any idea ? how can i do this in my configuration file?
As #amicoderozer is asking, if your classes share a common base package you only must indicate that root package.
If it's not your case (despite you are loading from a config file or you are declaring them manually) maybe the problem (will help posting any Exception or Runtime trace) is the way the split method is used. It returns an array, and I guess the generated code will be like this:
#EnableJpaRepositories("jpa.repository.packages1","jpa.repository.packages2")
That code doesn't compile.
Never tried Spring EL inside the annotation of a component, but despite this, maybe you should indicate the basePackages this way:
#EnableJpaRepositories(basePackages = "#{'${jpa.repository.packages}'.split(',')}")
If doesn't work, I recomend you first test it by manual array declaration:
#EnableJpaRepositories(basePackages = { "com.epms.model","com.ecms.model" })
Be sure all works as you expect, and then try again reading and parsing from config file.
UPDATE:
After some readings, I've concluded that is not possible do what you want. The SpEL is allowed in many places but for annotations there is only documentation and working examples with #Value annotation.

Related Links

spring mongo querydsl Can't find a codec for class java.time.LocalDateTime
Getting org.springframework.data.mapping.model.MappingInstantiationException after a restart of the application
Customizing Param Binding for QueryDSL Support
Bean name is ambiguous matches same bean twice
Error upgrading to Mongo java driver 3.2.2
Spring Data Redis: Setting a Password
Spring Data QueryDSL predicate two table join specification
specification groupBy in query and pagination
Spring Repository: get number of deleted rows
SpringData PageImpl totalElements is wrong
Spring Data MongoDB. Custom #Query with current date
Spring Data - Mongo DB - search
How to query using fields of subclasses for Spring data repository
Spring Data Elasticsearch Parent/Child Document Repositories / Test execution error
DynamoDB FilterExpression find all foreign keys that contain a set of attributes
Toplink release UnitOfWork Resources

Categories

HOME
qt
elasticsearch
office365
apache-nifi
macos-sierra
matrix
xcode
angular-ui-grid
opencv-python
key
dry
initialization
tabs
cryptography
angular2-template
tweepy
scheduler
eddystone
solution
orc
android-externalstorage
feature-extraction
pygobject
closures
adobe-illustrator
el
kaggle
qa
websphere-portal
jpa-2.1
xdebug
spring-annotations
premake
series
om-next
nest
polyml
pdfminer
textmate2
subclassing
cargo
installanywhere
recovery
morphline
git-tfs
doctrine-extensions
absolute
brightscript
beeline
redisson
punctuation
freshdesk
android-mediarecorder
ptvs
email-forwarding
multi-touch
carmen
system.net.mail
between
fragmentstatepageradapter
codecharge
swiffy
polymerfire
teamviewer
android-expansion-files
python-cffi
google-maps-api-2
nette
bjam
mixins
enaml
wlanapi
green-threads
com0com
signed
phonegap-facebook-plugin
lifetime
box2dweb
accessory
jini
zend-search-lucene
webaii
accountmanager
profiles
autonumber
lru
acceptance-testing
jquery-lazyload
semicolon
first-class
boost-foreach
suphp
getimagesize
index.dat
rakudo
twitter-feed
objectinstantiation

Resources

Mobile Apps Dev
Database Users
javascript
java
csharp
php
android
MS Developer
developer works
python
ios
c
html
jquery
RDBMS discuss
Cloud Virtualization
Database Dev&Adm
javascript
java
csharp
php
python
android
jquery
ruby
ios
html
Mobile App
Mobile App
Mobile App