简体   繁体   中英

Is it necessary to create both application-context.xml and application-servlet.xml in a single application?

  • Why do we require a application-servlet.xml at all ?
  • Why is application-context.xml alone insufficient?

It not necessary but recommended. Using separated configuration files you can isolate the web from the other world for security reasons(eg more secure). You can make a spring-boot program even without a single configuration file by annotations.

The application context is a bigger context, it means the beans defined in this context can be referred by servlet context but not vice versa.

Separation of concerns is just a best practice. No fire will suddenly appear if you ignore it, but you will have harder to maintain code. And if you carefully design your application with a web layer a service layer and a persistence layer, storing the beans in the proper application context will just make things simpler.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM