Jun 04 2009

Spring logging config

Published by Gilles under J2EE, Java, Spring

spring25.png

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 implementation:

In your application context, add a CommonsLogFactoryBean and give it a logName.

XML:
  1. <bean id="logger" class="org.springframework.beans.factory.config.CommonsLogFactoryBean">
  2.  
  3. <property name="logName" value="log"/></bean>

In your web., add the org.springframework.web.util.Log4jConfigListener listener before the
org.springframework.web.context.ContextLoaderListener

XML:
  1. <context-param>
  2. <param-name>log4jConfigLocation</param-name>
  3. <param-value>WEB-INF/.properties</param-value>
  4. </context-param>
  5. <listener>
  6. <listener->org.springframework.web.util.Log4jConfigListener</listener->
  7. </listener>

Here, my log4j config is locatedin the WEB-INF/.properties and here is its content:

XML:
  1. log4j.rootCategory=DEBUG, CONSOLE# CONSOLE is set to be a ConsoleAppender using a PatternLayout.
  2. log4j.appender.CONSOLE=org.apache..ConsoleAppender
  3. log4j.appender.CONSOLE.Threshold=DEBUG
  4. log4j.appender.CONSOLE.layout=org.apache..PatternLayout
  5. log4j.appender.CONSOLE.layout.ConversionPattern=- %m%n
  6. log4j.category.net.sf.=DEBUG
  7. 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 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:
  1. <context:annotation-config/>

tag to enable the annotations config.In the targets beans, annotate the member variable as follow:

JAVA:
  1. @Autowired @Qualifier("logger")
  2. private final Log logger = null;

No responses yet

Apr 26 2009

Hibernate statistics on Tomcat with JMX

Published by Gilles under Hibernate, J2EE, Java

This little snippet will show you how to get Statistics MBean available.

Inside the tomcat startup script (bin/tomcatXw.exe), ensure that the following _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 config, add:

XML:
  1. <bean id="jmxExporter" class="org.springframework..export.MBeanExporter"></bean>
  2.  
  3. <property name="beans">
  4. <map>
  5.     <entry key=":name=statistics">
  6.      <ref local="statisticsBean"/>
  7. </entry>
  8. </map>
  9. </property>
  10. <bean id="statisticsBean" class="org...StatisticsService"/>
  11. <property name="statisticsEnabled"><value>true</value></property>
  12. <property name="sessionFactory"><ref local="sessionFactory"></ref></property>

and then set the .generate_statistics property:

XML:
  1. <prop key=".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 , if you double click on that node, you should see the Statistics Bean.

No responses yet

Feb 26 2009

Sending email with Spring and Velocity

Published by Gilles under J2EE, Java, Programming, Spring

spring25.png velocity-logo.png

I'll try to explain how it can be easy to create an email service that uses and to send mails.
First of all, what do you need in your classpath?

  • activation.jar
  • mail.jar
  • spring.jar
  • velocity.jar

I'm using 2.5 and 1.5.

Pages: 1 2 3 4 5 6 7

One response so far

Feb 17 2009

Accessing Spring application context in MDB’s

Published by Gilles under J2EE, Java, Spring

spring25.png
Let's say you have a message driven bean in which you want to inject beans.

Add an interceptor

Annotate your with the @Interceptors and specify SpringBeanAutowiringInterceptor. as interceptor. This is an 3-compliant interceptor that injects 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 beans from is determined by the getBeanFactory(.lang.Object) template method. The default implementation obtains the ContextSingletonBeanFactoryLocator, initialized from the default resource location classpath*:beanRefContext., and obtains the single ApplicationContext defined there.
(for more info, see doc)

Pages: 1 2 3

No responses yet

Feb 16 2009

Spring annotations based config

Published by Gilles under J2EE, Java, Spring

spring25.png

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 configuration files is reduced drastically.

Pages: 1 2 3 4 5

No responses yet

Feb 16 2009

Exposing MBeans with Spring

Published by Gilles under J2EE, Java, Spring

spring25.png
Spring could be an alternative to expose Mbeans (see doc).
The support in Spring provides you with the features to easily and transparently integrate application into a infrastructure.

Specifically, 's support provides four core features:

  • The automatic registration of any bean as a 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

4 responses so far

Oct 04 2008

Getting started with Apache tiles2 and struts2

Published by Gilles under Java, Programming, Struts, Web

tiles struts2.png
Apache Tiles is a templating framework built to simplify the development of web application user interfaces.

Requirements

To use in your application you need:

  • a Runtime Environment following the Java SE 5.0 specifications;
  • a servlet container that supports Servlet 2.4 (or above) and JSP 2.0 (or above).

Pages: 1 2 3 4

No responses yet

Mar 13 2008

Spring AOP with aspectJ and JDK5 annotations

Published by Gilles under Spring

spring25.png
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 (even through method calls) which makes maintenance and evolution not easy.

Pages: 1 2 3 4 5 6

No responses yet

Dec 24 2007

Javapolis 2007

Published by Gilles under Conferences, Java

javapolis07.jpg
Wednesday December 12th, I went to the Javapolis 2007 edition. After some troubles finding the right tram to go to the right place, I finally catch... the right bus! Arriving at the entrance, I met a colleague of mine, that had a very bad news: "they don't know us!". After some phone calls, we ended up to find our two badges in a partner stand. (We will have to thanks our boss!)

No time for food, James Gosling's speech, "The state of the java universe", will begin in a few. Three rooms totally full listened to James attentively. We had news about Java, Fx andNetbeans + a cool demo with 2 funny robots.

The second conference, I saw was the new SoapUI presentation by Ole Matzura. As a developer, I did not find it very useful but it seems to be really a nice tool for testers.

Time to eat now! I met a colleague of mine wandering for his accreditation :) After getting it, we began the endless queue to get our lunch disappointing hot dogs. Really, that did not do it!
After this, we went to see the Google web toolkit presentation by Dick Wall. A tool that lets you build applications by converting into javascript. Very interesting, but the demo was a little bit confused.

The next conference I saw was the "SOA Development using JBossESB" by MarkLittle. His presentation was very clear! He explained the place of and (two buzzwords of choice today...) in the development process an their places in the WS-* architecture.

The last conference I saw was "JSR 318 - Enterprise JavaBeans 3.1" by Kenneth Saks. Too tired, I had to leave at the half of the presentation. (I had still to catch a bus and two trains to come back home...).

Finally what I liked:

  • the quality of the conferences I saw
  • the whiteboards concept

... and what I didn't like:

  • the lunch queue
  • the lunch
  • the commercial (but normal) part (stands)

No responses yet

Dec 20 2007

About

Published by Gilles under Uncategorized

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, 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 et ses frameworks... Enjoy and feedback!

No responses yet

Next »