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

How to render UI through JavaFX in an Eclipse RCP application?
configuration.yml has an error: * Unrecognized field at: driverClass - DROPWIZARD
Error 500 failed to retrieve in ud859 course
How to detect the mouse cursor/click in a previously recorded video/image frame
search and sort list of objects
Mergesort lines from a .txt file
Checking for in-app purchases
Android: MVP. Right way to communicaticate between components
how to exclude all modules of a dependency?
Display all images from Database (blob) on a jsp file in a table
how to avoid GC pauses?
Empty ListView doesn't appearance style
Realm Result returning null
How to use classes in android [closed]
int cant be converted into resultSet
Spring: Singleton that should be loaded initialized at startup

Categories

HOME
vim
winforms
pdf
webpack
oracle11g
onedrive
dot
tesseract
jpeg
paradox
append
metatrader4
remote-access
phaser
jsdoc
google-static-maps
undefined
dbext
conemu
tar
excel-2007
h2db
dynamic-featured-image
large-file-upload
windows-server-2000
ecto
uisplitview
functor
siesta-swift
jspresso
gtrendsr
y86
bytecode-manipulation
suricata
bitbucket-pipelines
xcode-extension
splice
cookiecutter-django
preconditions
android-tabhost
eclipse-scout
hibernate-tools
ionicons
snmptrapd
color-picker
database-optimization
multi-level
underscore.js-templating
player
ios4
revolution-r
ios8-today-widget
ora-00900
jmeter-maven-plugin
quicklisp
computer-algebra-systems
kcachegrind
embedded-code
iiviewdeckcontroller
dundas
graph-api-explorer
skos
e10s
kineticjs
c3
asp.net-dynamic-data
code-access-security
navigationservice
hippomocks
balanced-payments
stxxl
sitemesh
web2py-modules
file-locking
batterylevel
rabl
ember-app-kit
sabredav
lcs
tinn-r
chuck
gil
word-processor
propertyeditor
newtonscript
nsmanagedobject
removeclass
netdna-api
fireworks
datareader
visitor-statistic
thunderbird-lightning
multi-tier
backcolor
mtj
temporal-database
premature-optimization
uiq3

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