java


Spring boot is not identifying rest repositories


I'm using spring data rest(1.3.5.RELEASE) to create a simple rest service.
But the repository/JPA entities are not being recognized/registered, when my Application Config resides at a different package level.
Here is my sample project structure:
<source.root>
- package1
- Application.java
- package2
- RepositoryService.java
- Model.java
In this case the RepositoryService is not exposing any rest methods.
Change in my project structure as below solves this problem.
<source.root>
- package1
- Application.java
- package2
- RepositoryService.java
- Model.java
Is it mandatory for spring boot Application config to be present at the top level, so that it can scan the beans ?
If Application.java is main Spring Boot class, it most probably uses #SpringBootApplication annotation.
This annotation is composite annotation and contains also #ComponentScan annotation under the hood.
Now component scan by default scans current package and all the sub-packages. So with your first project structure, you excluded repositories from component scan.
To solve it you have these options:
Use project structure 1 and explicitly define packages to scan: #SpringBootApplication(scanBasePackages = "package2"). This is not type safe
Use project structure 1 and and explicitly define class from package you want to scan: #SpringBootApplication(scanBasePackageClasses = RepositoryService.class). This is better option than option 1 as it is typesafe
Stick with opinionated Spring Boot defaults and use project structure 2.
Bear in mind, Spring Boot will be your best friend if you don't try to fight against its opinionated defaults. Only if you have really unbeatable reason.

Related Links

Camera.open() error -13 on emulator
Explanation of AES/CFB code part [closed]
Scanning through ArrayList for Objects with same field
Regex code in java code
Java — Objects & calling methods
Bug in OS X with JFileChooser UI (?)
What determines whether a JDialog closes when the main JFrame does?
Use webservice in Android
How to implement tablemodel in java?
Jackson parse array inside array
Java - is there a thread safe way to allocate new objects without locks?
Java deployment process
Developing and testing an OpenCV application on desktop which should later run on Android
how can I get layout like added image?
How do I pass an implemented Interface object to a method in the class its implemented in?
only the first client request arrives to the server when using java sockets

Categories

HOME
ibm-bluemix
ionic-framework
multithreading
bluetooth
gerrit
openmp
proxy
activiti
dot
react-router
spring-cloud-stream
spring-jdbc
cakephp-2.5
ravendb
ojdbc
onelogin
azure-media-services
indesign
android-youtube-api
kentor-authservices
izpack
postgres-xl
msp430
dynamics-crm-online
caml
vaadin7
clojurescript
graphlab
facebook-page
solaris-10
normalizr
reverse-proxy
autocad-plugin
css-animations
realex-payments-api
mmap
tibco-mdm
javacv
spring-mybatis
windows-server-2000
objectanimator
c++-amp
delicious-api
srcset
microsoft-chart-controls
airconsole
siesta-swift
commit
normal-distribution
mmenu
picasso
fusionpbx
devextreme
dosbox
qwerty
trim
android-tabhost
quadratic-programming
glew
botbuilder
nxlog
node-sass
upstart
pango
paxos
ionicons
git-diff
aurelia-validation
darcs
pg-dump
font-size
sqlbulkcopy
mcafee
thrust
mathematica-frontend
fuzzy-search
photobucket
tcpserver
srand
atk4
muse
mono-embedding
remobjects
unity5.2.3
csquery
tween
mysql-error-1062
braille
ivyde
.aspxauth
buster.js
django-nonrel
orchardcms-1.7
free-variable
onsubmit
postgresql-performance
dotnethighcharts
imac
visitor-statistic
google-friend-connect
nhibernate.search
meego
microsoft-virtualization
javap
ti-dsp
phonon
aquaticprime
ugc

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