Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Small tip - I've found it helpful to modularize and clearly label my Spring xml context files based on application concern. Here's an example for a web app I worked on:</p> <ul> <li><code>MyProject / src / main / resources / spring /</code> <ul> <li><em><strong>datasource.xml</strong></em> - My single data source bean.</li> <li><em><strong>persistence.xml</strong></em> - My DAOs/Repositories. Depends on <code>datasource.xml</code> beans.</li> <li><em><strong>services.xml</strong></em> - Service layer implementations. These are usually the beans to which I apply transactionality using AOP. Depends on <code>persistence.xml</code> beans.</li> <li><em><strong>controllers.xml</strong></em> - My Spring MVC controllers. Depends on <code>services.xml</code> beans.</li> <li><em><strong>views.xml</strong></em> - My view implementations.</li> </ul></li> </ul> <p>This list is neither perfect nor exhaustive, but I hope it illustrates the point. Choose whatever naming strategy and granularity works best for you.</p> <p>In my (limited) experience, I've seen this approach yeild the following benefits:</p> <p><strong>Clearer architecture</strong></p> <p>Clearly named context files gives those unfamiliar with your project structure a reasonable place to start looking for bean definitions. Can make detecting circular/unwanted dependencies a little easier.</p> <p><strong>Helps domain design</strong></p> <p>If you want to add a bean definition, but it doesn't fit well in any of your context files, perhaps there's a new concept or concern emerging? Examples:</p> <ul> <li>Suppose you want to make your Service layer transactional with AOP. Do you add those bean definitions to <code>services.xml</code>, or put them in their own <code>transactionPolicy.xml</code>? Talk it over with your team. Should your transaction policy be pluggable?</li> <li>Add Acegi/Spring Security beans to your <code>controllers.xml</code> file, or create a <code>security.xml</code> context file? Do you have different security requirements for different deployments/environments?</li> </ul> <p><strong>Integration testing</strong></p> <p>You can wire up a subset of your application for integration testing (ex: given the above files, to test the database you need to create only <code>datasource.xml</code> and <code>persistence.xml</code> beans).</p> <p>Specifically, you can annotate an integration test class as such:</p> <pre><code>@ContextConfiguration(locations = { "/spring/datasource.xml" , "/spring/persistence.xml" }) </code></pre> <p><strong>Works well with Spring IDE's Beans Graph</strong></p> <p>Having lots of focused and well-named context files makes it easy to create custom BeansConfigSets to visualize the layers of your app using Spring IDE's <a href="http://springide.org/project/wiki/BeansGraph" rel="noreferrer">Beans Graph</a>. I've used this before to give new team members a high-level overview of our application's organization.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload