Java Ninja Chronicles By Norris Shelton

Things I learned in the pursuit of code

In a previous post, I talked about Spring P-notation.  In this blog post, I will give an example of the Spring C-notation for constructor arguments.

The C-notation namespace needs to be added to your configuration file.


All that is left is to use it for a constructor argument

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns=""

    <!-- removed unnecessary configurations -->

    <bean id="requestFactory" class="org.springframework.http.client.HttpComponentsClientHttpRequestFactory"

    <bean id="restTemplate" class="org.springframework.web.client.RestTemplate"

December 29th, 2014

Posted In: Java

Tags: , , , , , , , , ,

Leave a Comment

We added Springframework to a legacy application. We encountered places where we needed access to Springframework beans by non-Spring beans. The Spring context was loaded by:

ApplicationContext context = new ClassPathXmlApplicationContext("applicationContext.xml");

The appeared to work fine, but what we did not realize until we looked at the logging was that the Spring context was refreshed every time this was called. This is a no-no when you have over 1000 classes under packages to be scanned.

The correct way is by:

ApplicationContext context = WebApplicationContextUtils.getRequiredWebApplicationContext(servletContext);

This worked for the Servlet API objects. We had some POJOs that did not have access to the Servlet API. We were already performing special processing via a filter to add various objects to the current context by using ThreadLocal.

April 4th, 2012

Posted In: Java, Spring

Tags: ,

Leave a Comment

LinkedIn Auto Publish Powered By :