Jun
04
2009

Spring uses Apache commons-logging as a bridge between different logging implementations.
This way you can change from a logging framework to any other supported loggin mechanism at any time.
The org.springframework.beans.factory.config.CommonsLogFactoryBean will create a "logger bean" and his type will depends on your configuration.
Example for the Log4j implementation:
In your application context, add a CommonsLogFactoryBean and give it a logName.
XML:
-
<bean id="logger" class="org.springframework.beans.factory.config.CommonsLogFactoryBean">
-
-
<property name="logName" value="log"/></bean>
In your web.xml, add the org.springframework.web.util.Log4jConfigListener listener before the
org.springframework.web.context.ContextLoaderListener
XML:
-
<context-param>
-
<param-name>log4jConfigLocation</param-name>
-
<param-value>WEB-INF/
log4j.properties
</param-value>
-
</context-param>
-
<listener>
-
<listener-class>org.springframework.web.util.Log4jConfigListener
</listener-class>
-
</listener>
Here, my log4j config is locatedin the WEB-INF/log4j.properties and here is its content:
XML:
-
log4j.rootCategory=DEBUG, CONSOLE# CONSOLE is set to be a ConsoleAppender using a PatternLayout.
-
log4j.appender.CONSOLE=org.apache.
log4j.ConsoleAppender
-
log4j.appender.CONSOLE.Threshold=DEBUG
-
log4j.appender.CONSOLE.layout=org.apache.
log4j.PatternLayout
-
log4j.appender.CONSOLE.layout.ConversionPattern=- %m%n
-
-
log4j.category.org.springframework =DEBUG
To make use of your logger in your other beans, add a member variable of type org.apache.commons.logging.Log
and configure Spring to inject the reference to the logger bean. For my part, I choose to do it through annotations because I don't want to have to make this reference in all my beans...
So, in your application context, add the
XML:
-
<context:annotation-config/>
tag to enable the annotations config.In the targets beans, annotate the member variable as follow:
JAVA:
-
@Autowired @Qualifier("logger")
-
private final Log logger = null;
Apr
26
2009
This little snippet will show you how to get Hibernate Statistics JMX MBean available.
Inside the tomcat startup script (bin/tomcatXw.exe), ensure that the following JAVA_OPTS are set:
JAVA_OPTS="
-Dcom.sun.management.jmxremote.port=9002
-Dcom.sun.management.jmxremote.authenticate=false
-Dcom.sun.management.jmxremote.ssl=false
-Djava.awt.headless=true"
In your Spring config, add:
XML:
-
<bean id="jmxExporter" class="org.springframework.jmx.export.MBeanExporter"></bean>
-
-
<property name="beans">
-
<map>
-
-
<ref local="statisticsBean"/>
-
</entry>
-
</map>
-
</property>
-
<bean id="statisticsBean" class="org.hibernate.jmx.StatisticsService"/>
-
<property name="statisticsEnabled"><value>true</value></property>
-
<property name="sessionFactory"><ref local="sessionFactory"></ref></property>
and then set the hibernate.generate_statistics property:
XML:
-
<prop key="hibernate.generate_statistics">true
</prop>
When you browse the MBeans (using JConsole.exe - which lives in the bin dir of your JDK 1.5 distribution), you should see Hibernate, if you double click on that node, you should see the Statistics Bean.
Feb
26
2009

I'll try to explain how it can be easy to create an email service class that uses Spring and Velocity to send mails.
First of all, what do you need in your classpath?
- activation.jar
- mail.jar
- spring.jar
- velocity.jar
I'm using Spring 2.5 and Velocity 1.5.
Pages: 1 2 3 4 5 6 7
Feb
17
2009

Let's say you have a message driven bean in which you want to inject spring beans.
Add an interceptor
Annotate your MDB with the @Interceptors and specify SpringBeanAutowiringInterceptor.class as interceptor. This is an EJB3-compliant interceptor class that injects Spring beans into fields and methods which are annotated with @Autowired. Performs injection after construction as well as after activation of a passivated bean.
The actual BeanFactory to obtain Spring beans from is determined by the getBeanFactory(java.lang.Object) template method. The default implementation obtains the Spring ContextSingletonBeanFactoryLocator, initialized from the default resource location classpath*:beanRefContext.xml, and obtains the single ApplicationContext defined there.
(for more info, see doc)
Pages: 1 2 3
Feb
16
2009

It is now possible to configure Spring's dependency injection with annotations. This means that annotations can be used in Spring to mark fields, methods and classes that need dependency injection. Spring also supports auto-wiring of the bean dependencie. Annotations can also be used to indicate fields that are to be auto-wired. Furthermore, auto-detection of annotated components in the classpath is also supported now. When these capabilities are combined, the amount of configuration and dependency mapping in the Spring configuration files is reduced drastically.
Pages: 1 2 3 4 5
Feb
16
2009

Spring could be an alternative to expose Mbeans (see Spring doc).
The JMX support in Spring provides you with the features to easily and transparently integrate Spring application into a JMX infrastructure.
Specifically, Spring's JMX support provides four core features:
- The automatic registration of any Spring bean as a JMX MBean
- A flexible mechanism for controlling the management interface of your beans
- The declarative exposure of MBeans over remote, JSR-160 connectors
- The simple proxying of both local and remote MBean resources
Pages: 1 2 3 4 5
Mar
13
2008

Introduction
The aspect-oriented programming (AOP) paradigm attempts to help programmers in the separation of concerns, specifically cross-cutting concerns, as an advance in modularization that comes beside the OO paradigm.
Examples of these "cross-cutting concerns" can be:
- Security
- Transactions
- Logging
- etc.
With the traditional OO approach, these functions have to be implemented in each concerned class (even through method calls) which makes maintenance and evolution not easy.
Pages: 1 2 3 4 5 6
Dec
20
2007
Difficile d’annoncer le programme d’un blog qui ne se veut pas forcément centré sur un sujet précis. Travaillant depuis plusieurs années « dans le web », l’envie m’a pris seulement il y a quelques temps, au détour de quelques blogs bien faits.
Concernant le choix de l’outil, pas vraiment de doutes. Ayant déjà installés et adaptés différents systèmes de blogs, WordPress fut l’usual suspect, tant pour sa flexibilité (thèmes et plugins) que pour son backoffice sobre et intuitif.
J’ai installé celui-ci sur une Gentoo (Apache 2, PHP 5, MySQL 5) en moins de temps qu’il n'en faut pour le dire. Ca tourne plutôt bien !
Mon leitmotiv: le faire bien sans se prendre la tête. Partager mon expérience quotidienne de java et ses frameworks... Enjoy and feedback!