spring-boot


Difference between #EntityScan and #ComponentScan


I am trying to understand the difference here. I see that a class has been annotated with both of them with same package example :
#Configuration
#EntityScan("some.known.persistence")
#ComponentScan({ "some.known.persistence"})
public class ApiConfig {
}
I understand the differences from API docs but want to understand in detail. Also does it mean that anything that is scanned by #ComponentScan is having wider visibility wrt Spring context and #EntityScan does not. If so using some attribute with #ComponentScan should have sufficed the need to bind in a JPA context, isn't it?
The #ComponentScan annotation is used to automatically create beans for every class annotated with #Component, #Service, #Controller, #RestController, #Repository, ... and adds them to the Spring container (allowing them to be #Autowired).
The #EntityScan on the other hand does not create beans as far as I know. It only identifies which classes should be used by a specific persistence context. Since Spring boot 1.4 that includes JPA, MongoDB, neo4j, Casscandra and CouchBase.
Why they're not merged? Well, I'm not a developer, but my guess is that they have different meanings, so why should they? The #EntityScan should mainly be used to scan your entity packages, while the #ComponentScan should scan all packages that contain Spring beans, so the following is very likely:
#ComponentScan("org.example.base")
#EntityScan("org.example.base.entities")
public class MyConfig {
}
#EntityScan is a deprecated annotation used to identify JPA entities, i.e. persistent classes, from a database point of view.
You use #ComponentScan to search for components, from a Spring point of view, i.e. classes(also know as Java Beans) annotated with #Component, #Service, #Repository, #Controller... These are Spring components added to the IoC container.

Related Links

Spring Boot Batch use case for jobParameters and #JobScope/#StepScope over Environment/#ConfigurationProperties when configuring readers and writers?
CORS Origin Spring Boot Jhipster - pre-flight fails
Over writing server port of the application.yml in the command line
Reload javascript after thymeleaf fragment render
Feign/Eureka client not passing X-Forwarded-For header
Spring-Boot, how to start it manually in a servlet 3.0 environment
html form validation using thymeleaf not working spring boot
Spring Boot logging with logback
Spring #Query with principal and ternary operator
Is there a way a spring cloud config client can decrypt cipher text fetched from a config server?
How to get method information at Interceptor preHandle method in spring boot 1.3
Spring Boot Microservices Deployment
Starting Spring Application by merging yml files
Spring Integration with Jackson ObjectMapper and Java 8 Time (JSR-310)
Spring boot not serving static content when Jersey REST is included
how to base url and access application.properties whsn using Vaadin Spring boot 1.0.0

Categories

HOME
logging
network-programming
gsm
xamarin.forms
azure-database-mysql
watson-iot
spss
docker-compose
genexus
box-api
openbsd
logstash-configuration
swift3.1
multibinding
samba
google-calendar-api3
geography
aiml
legend-properties
caldav
single-page-application
wai-aria
quality-center
ecmascript-2017
sqldependency
edirectory
arp
edsdk
zimbra
bootcamp
flex3
repeat
campaign-monitor
outlook-2010
form-fields
observer-pattern
fisheye
google-cloud-powershell
pyexcel
datagridviewcombobox
python-venv
hdpi
confluent
spring-cloud-bus
flask-socketio
monaca
appcmd
e4
vertex
enet
aot
typewriter
nsalert
multi-select
qt3d
addressbook
easy68k
ldd
patching
bytearray
weblogic-maven-plugin
boost-bind
radar-chart
gitk
edgar
self-join
first-order-logic
properties-file
eggplant
eula
vspackage
cakephp-2.6
wingdb
zoneminder
reactjs-native
android-relativelayout
object-oriented-database
oc4j
dynamic-expresso
http-compression
cloudmade
pageload
biztalk-deployment
phone-state-listener
ntdll
inflate
github-archive
jqueryi-ui-buttonset
openwrap
html5-animation
excellibrary
datarelation
code-golf
large-data-volumes
dynamic-scope
data-formats
authkit
projectgen

Resources

Encrypt Message