Win a copy of Terraform in Action this week in the Cloud forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Tim Cooke
  • Campbell Ritchie
  • Paul Clapham
  • Ron McLeod
  • Liutauras Vilda
Sheriffs:
  • Jeanne Boyarsky
  • Rob Spoor
  • Bear Bibeault
Saloon Keepers:
  • Jesse Silverman
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
Bartenders:
  • Piet Souris
  • Al Hobbs
  • salvin francis

Spring Java Config file question

 
Ranch Hand
Posts: 71
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I have some Spring Java config files I'm looking at. The main configuration file is


The WebConfig.java file is:



The DataConfig.java file is:



and the RootConfig.java file is:



Could someone explain the RootConfig.java file to me, specifically what the static class WebPackage is doing. I know RegexPatternTypeFilter is used to set up a simple filter for matching on a regex expression, but what is happening here when this class is just created and it's .match(...) method is not being obviously called anywhwere? Thanks in advance.
 
Ranch Hand
Posts: 43
Spring Tomcat Server Chrome
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Mike,

If the code is from a book (like Spring In Action), I think you should quote that it is so, to be fair to the book owners.

Anyway, the @ComponentScan have the excludeFilters, and excludeFilters uses that WebPackage.class.

WebPackage is a custom filter.

Basically anything that matches below, is excluded from the component scanning.

 
Mike Tabak
Ranch Hand
Posts: 71
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

John Cruz wrote:Hi Mike,

If the code is from a book (like Spring In Action), I think you should quote that it is so, to be fair to the book owners.

Anyway, the @ComponentScan have the excludeFilters, and excludeFilters uses that WebPackage.class.

WebPackage is a custom filter.

Basically anything that matches below, is excluded from the component scanning.



Hi John,

Yes, this is from Spring In Action Volume 4. What you say makes sense. The version I quoted is from the downloadable source code. The version of this file printed in the text does the same thing, only without the WebPackage class definition, it just uses an excludeFilter definition based on annotation and class. When I substituted that file for the one in the download, things still worked fine. I guess when you component scan for the root config you have to be sure not to include any definitions in the DispatcherServlet config. Thanks much John.
 
John Cruz
Ranch Hand
Posts: 43
Spring Tomcat Server Chrome
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Mike,

The root config thing is shared by all lower configs. I mean, the root application context created from it, is inherited by all application contexts in the application.

There is only 1 root application context in the application. You usually put there only stuff that is used in entire application.

The web stuff is not used in entire application but by the web stuff only (like web layer, controllers; but not used for example by JMS layer services). That is why the coder of that sample code, excluded it from the root context, which is inherited by all lower contexts.

In the WebConfig in the sample code, that spitter.web is component-scanned in it, and therefore beans in the spitter.web are registered in the web application context.

All this magic starts at below:
 
You showed up just in time for the waffles! And this tiny ad:
Building a Better World in your Backyard by Paul Wheaton and Shawn Klassen-Koop
https://coderanch.com/wiki/718759/books/Building-World-Backyard-Paul-Wheaton
reply
    Bookmark Topic Watch Topic
  • New Topic