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

How to properly use Locking or Transactions to prevent duplicates using Spring Data
How to create specification using JpaSpecificationExecutor by combining tables?
Is it possible to use spring-data-rest-webmvc without an actual Repository?
Couchbase - Eviction
Variables with underscores create compile error within derived query methods (spring-data)
Weblogic 12 + Spring Data JPA + CDI issues
Javascript CRUD Admin for Spring-Data HATEOAS backend
Spring HATEOAS Link with Matrix Variable Not Working
Spring bean name clash Hibernate/Proguard?
How to specify Schema name while using #NamedStoredProcedureQuery
Spring Data Joda Time Duration Type store in mongoDB
Spring JpaRepository how to query a #ManyToMany entity
What is the difference between findAllBy and readAllBy?
How to make index name to resolve dynamically
Querying Tables with Composite Primary Keys using Spring-data-cassandra
#QuerydslPredicate in spring test fails in standaloneSetup

Categories

HOME
entity-framework
class
functional-programming
clearcase
openxml
focus
eclipse-plugin
livecode
ews
apk
vsts-build
histogram
twitter-fabric
dronekit-python
portable-class-library
drag-and-drop
gprs
cisco
selection
fireloop
parsley.js
watch-os-3
bundler
jodatime
twisted
boomi
maven-surefire-plugin
mime-types
eclipse-emf
introspection
spreadsheetgear
tf-idf
onchange
annotation-processing
php-5.3
pyspark-sql
sendmessage
autodesk-model-derivative
rspec-rails
knights-tour
cucumber-junit
payeezy
grails-2.5
numerics
telephonymanager
linq.js
best-buy-api
angular-datatables
robust
jqgrid-asp.net
permission-denied
type-inference
adblock
tinyioc
ilrepack
jgrapht
iptv
punctuation
pen
business-rules
cognos-tm1
gawk
petsc
metabase
visual-studio-monaco
fragmentstatepageradapter
qpixmap
android-async-http
gridbaglayout
cortana
boost-proto
dnx50
pythonxy
espresso
postal-code
modern.ie
swagger-maven-plugin
ocmockito
prism-4
famo.us
cout
oracle-adf-mobile
webmethod
communicate
treeline
rpg
wso2bam
compiler-flags
mute
insertonsubmit
coalesce
hints
xs
spiral
semicolon
significant-digits
user-forums
zend-pdf
workflow-manager-1.x
border-box
java.lang.class
prototypal-inheritance
algol68
radscheduler
regression-testing
aptitude
chunking
resharper-5.1
iphone-sdk-4.3
version-control-migration
stretchblt

Resources

Database Users
RDBMS discuss
Database Dev&Adm
javascript
java
csharp
php
android
javascript
java
csharp
php
python
android
jquery
ruby
ios
html
Mobile App
Mobile App
Mobile App