martedì, dicembre 22, 2009

La neve, Spinea e Andrea

Enrico, scrivi qualcosa cribbio!
"Tornando da una seratina passata al lume di candela con la fata Monia, incontrai Andrea. Ma che ci fa Andrea da solo, alle 22, davanti ad un cassettone delle immondizie, in tuta da ginnastica? Era uscito a buttare la spazzatura ?"
Ma che ne so Enrico inventa!
(Testo della mail di Andrea...scusate ma sono troppo pigro ultimamente :) )


giovedì, dicembre 17, 2009

Deploying Spring @Component annotated application in JBoss 5.1

I've spent the last few days fighting with jboss 5.1 trying to deploy a spring based web application using the Component annotation.
The application as opposed works using Tomcat 6.
Basically the spring context was not able to find the definition of SchedulerBo which is my Component annotated class.

package webscheduler.bo;

@Component
public class SchedulerBo {
...............................
}

This is the section of my spring configuration file which allows the spring context to auto-scan the schedulerBo.

<context:component-scan base-package="webscheduler.bo"/>

This is the exception I had.

19:17:09,706 ERROR [ContextListener] Error in base ContextListener.contextInitialized
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'jobNormal' defined in ServletContext resource [/WEB-INF/schedulerContext.xml]: Cannot resolve reference to bean 'schedulerBo' while setting bean property 'jobDataAsMap' with key [TypedStringValue: value [schedulerBo], target type [null]]; nested exception is
org.springframework.beans.factory.NoSuchBeanDefinitionException: No bean named 'schedulerBo' is defined

............................................................

Caused by: org.springframework.beans.factory.NoSuchBeanDefinitionException: No bean named 'schedulerBo' is defined at org.springframework.beans.factory.support.DefaultListableBeanFactory.
getBeanDefinition(DefaultListableBeanFactory.java:387)

This is the main section of my listener (ServletContextListener) class which I used to load the spring context(marked in red the row to change)

private WebApplicationContext applicationContext;
.....................................
config.add("WEB-INF/schedulerContext.xml");
XmlWebApplicationContext ctx = new XmlWebApplicationContext();
ctx.setServletContext(servletContext);
ctx.setConfigLocations(config.toArray(new String[config.size()]));
ctx.refresh();
applicationContext = ctx;

To sort out this problem you have to use org.jboss.spring.factory.VFSXmlWebApplicationContext instead of rg.springframework.web.context.support.XmlWebApplicationContext.
Therefore I changed this row in my listener.

XmlWebApplicationContext ctx = new org.jboss.spring.factory.VFSXmlWebApplicationContext();

Here the steeps to follow to solve the problem:

  1. Add this dependency to your pom, be sure to have the jboss repository in your pom.xml


    <dependency>
    <groupId>org.jboss.snowdrop</groupId>
    <artifactId>snowdrop-vfs</artifactId>
    <version>1.0.0.GA</version>
    <exclusions>
    <exclusion>
    <groupId>org.springframework</groupId>
    <artifactId>spring-core</artifactId>
    </exclusion>
    <exclusion>
    <groupId>org.springframework</groupId>
    <artifactId>spring-context</artifactId>
    </exclusion>
    <exclusion>
    <groupId>org.springframework</groupId>
    <artifactId>spring-beans</artifactId>
    </exclusion>
    <exclusion>
    <groupId>org.springframework</groupId>
    <artifactId>spring-web</artifactId>
    </exclusion>
    </exclusions>
    </dependency>


  2. Using VFSXmlWebApplicationContext in your listener class in this way

    XmlWebApplicationContext ctx = new org.jboss.spring.factory.VFSXmlWebApplicationContext();

  3. run $ mvn clean install and deploy the new generated war into <JBOSS_HOME>/server/default/deploy


This is the link in JBoss JIRA which reports the bug and shows the solution.

lunedì, marzo 23, 2009

skip maven test

In order to skip the test you have to add the parameter -Dmaven.test.skip=true when you run the mvn from command line.


$ mvn -Dmaven.test.skip=true clean install


Do not forget to add the clean goal before install, otherwise the test will be executed anyway
It seems to be a strange behaviour of maven.

lunedì, febbraio 23, 2009

Validate xml against the schema

The code is a an adjustment of what published in this post, just using InputStream instead of File as arguments for schema and xml.

public static void validateXMLAgainstSchema(InputStream xmlStream, InputStream schemaStream) throws SAXException, SAXParseException, ParserConfigurationException, IOException {

SchemaFactory schemaFactory = SchemaFactory.newInstance( XMLConstants.W3C_XML_SCHEMA_NS_URI );
schemaFactory.setErrorHandler( new DefaultHandler());
Schema schemaXSD = schemaFactory.newSchema(new StreamSource(schemaStream));
Validator validator = schemaXSD.newValidator();
DocumentBuilder parser = DocumentBuilderFactory.newInstance().newDocumentBuilder();
Document document = parser.parse(xmlStream);
validator.validate( new DOMSource( document));
}

giovedì, febbraio 05, 2009

Monologo fantastico


caro Jack ho conosciuto un capitano dell' aviazione, ci siamo innamorati. Voglio il divorzio per potermi risposare con lui, so che puoi negarmelo ma te lo chiedo lo stesso in nome di tutto quello che ci ha unito, dei ricordi. Perdonami...Jack c'era troppa solitudine. Un giorno ci rincontreremo, persone che sono state così vicine come noi si rincontrano sempre. Non ho alcun diritto di dirti queste cose, ma non riesco ad impedirmelo. E' un legame così difficile da spezzare.
Oh compagno di tutti quegli anni splendenti aiutami a lasciarti.

venerdì, gennaio 09, 2009

spring message tag libray

If you are using spring message tag library you know how much is annoying get a runtime exception in the case you have inserted a wrong code as attribute.
For every message code tag library you define in your jsp you have to add the corresponding property entry in the message.properties file but can happen you forget to insert it or maybe you insert a wrong value.
For example having such tl message where the code is Email

<spring:message code="Email" />

I have to define the corresponding entry in the file message.properties, or in more files depending on the type of internationalization I use.

Email=E-Mail

A way to avoid to get the runtime exception, in case of wrong code, is to add the property text to the message tl. In case of not matching the value of text will appear in the page and you could fix the problem after. Better to use text property with ? before and after the string so that you can easily understand there is a wrong value of code.
Therefore use

<spring:message code="Email" text="?Email?"/>

As usual, thanks to Lucio.