java - Necessary to use spring-core and spring-context dependencies together in a Spring project? -


i beginner in spring , trying learn reading codes scattered around on internet. when @ pom.xml of these codes, see people use "spring-core" , "spring-context" next each other added dependencies project. when @ dependency hierarchy, see spring-core in spring-context.

so question: necessary use both? there difference between "spring-core" in "spring-context" , "spring-core" separate artifact?

this called transitive dependency. if don't declare spring-core, still it, since spring-context declares it.

your code work, today, whether declare spring-core or not, because anyway transitive dependency mechanism. issue of best practice, not of whether works or not.

the question ask is, why need spring-core?

  • if code doesn't directly reference it, don't need it, if spring-context does. so, let spring-context take care of declaring requires spring-core. don't declare yourself.
  • if code directly reference spring-core, need it, whether or not spring-context needs it. maybe in future version, spring-context won't depend on spring-core more. so, should declare spring-core.

in 1 sentence, should explicitly declare dependencies use yourself, if they're brought in transitively.

it's not important on toy project. makes long-term maintenance lot easier on big projects.

edit: spring-core , spring-context closely linked above advice doesn't matter. common case does matter when have library depends on logging package l. if own code uses l, you'd better declare dependency explicitly, because quite switch in future use different logging package. on other hand, it's not spring-context switch different provider functionality of spring-core...


Comments

Popular posts from this blog

blackberry 10 - how to add multiple markers on the google map just by url? -

php - guestbook returning database data to flash -

delphi - Dynamic file type icon -