Thursday, July 26, 2007

Declarative transaction management with Spring 2 and AspectJ

I'm playing with Hibernate, Spring 2 and AOP. Configuring this stuff were some kind of challenge for me. But now it woks. I faced wery interesting exeption during configuration. Since I'm using Maven 2, Spring + Hibernate dependency looks like this:

<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-hibernate3</artifactId>
<version>2.0.5</version>
</dependency>

Exception is looks like this :

org.springframework.beans.factory.xml.XmlBeanDefinitionStoreException:
Line 63 in XML document from class path resource [applicationContext.xml] is invalid;
nested exception is org.xml.sax.SAXParseException: cvc-complex-type.2.4.c:
The matching wildcard is strict, but no declaration can be found for element 'aop:config'.
Caused by: org.xml.sax.SAXParseException: cvc-complex-type.2.4.c:
The matching wildcard is strict, but no declaration can be found for element 'aop:config'.
Strange ! I have appropriate configuration for namespaces at my applicationContext.xml :
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:aop="http://www.springframework.org/schema/aop"
xmlns:tx="http://www.springframework.org/schema/tx"
xsi:schemaLocation="
http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-2.0.xsd
http://www.springframework.org/schema/tx
http://www.springframework.org/schema/tx/spring-tx-2.0.xsd
http://www.springframework.org/schema/aop
http://www.springframework.org/schema/aop/spring-aop-2.0.xsd">
Config :
<aop:config>
<aop:advisor id="serviceTxAdvisor"
pointcut="execution(public *
com.company.service.impl.ServiceImpl.*(..))
"
advice-ref="txAdviceForService" />
</aop:config>

<tx:advice id="txAdviceForService"
transaction-manager
="transactionManager">
<tx:attributes>
<tx:method name="get*" read-only="true" />
<tx:method name="*" />
</tx:attributes>
</tx:advice>

Solution suggested at Spring forum doesn't work for me. I had no success with Xerces. So, I decided to digg a little more. As a result I've found two missing dependencies that should make me happy:
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-aop</artifactId>
<version>2.0.5</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-aspects</artifactId>
<version>2.0.5</version>
</dependency>

Weird exception vanished. I'm very happy now.

BTW, even you use spring dependency, you should add spring-aspects dependency as well to be able to use aop:config.

Thursday, July 19, 2007

Java developers for US Army

It seems to be that US army really using Java. At least they are recruting Java programmers. Take a look here.

Minimum requirements:

* Java, J2EE - at least 2-3 years
* Struts framework - at least 1 year
* Oracle, Sybase, DB2 or any other major database - at least 2 years
* XML - 1-2 years
* UML - at least general understanding
* Documentum - nice to have, no mandatory


Well, Struts +1 !

Military visitors ...

I haven't many visitors at my blog. But all of them are very interesting for me. Nevertheless, there are some that I couldn't expect to see. They are military. The most exciting is Pentagon. Here is screen shot of Google Analytics :

After some digging I have found others and here is complete list:

  1. usaisc-cecom : "The mission of the US Army Communications-Electronics Command (CECOM) is to develop, acquire and sustain superior information technologies and integrated systems, enabling battlespace dominance for America's warfighters."
  2. The Pentagon
  3. Office of the Chief of Naval Research
  4. Headquarters, USAAISC
I'm for peace :) Anyway, thanks for visit. It's still unclear for me what they attempt to find here. I'm not sure, but as far as I know, open source software is used in US army. Who knows :)

Tuesday, July 10, 2007

Build EJB3 with jBoss and Maven 2 - better solution

I'm working on project which is not in touch with EJB3, but Maven 2 is is used intensively. I remember my post about building EJB3 with jBoss and Maven 2. In fact that solution works, but I'm not satisfied with it. Since I'm became a little bit stronger in Maven 2 I decided to improve that solution.

So, the task is to build EJB3 entity and EJB3 session bean with Maven 2 and jBoss dependent jars. First, we setting up non another repository where Maven can find jboss jars :

<repositories>
<repository>
<id>jboss-maven2</id>
<url>http://repository.jboss.com/maven2</url>
</repository>
</repositories>

A little bit of magic should be added :)
<parent>                             
<groupId>jboss</groupId>
<artifactId>jboss-parent</artifactId>
<version>2</version>
</parent>

And finally, dependencies. JPA :
<dependency>                                  
<groupId>jboss</groupId>
<artifactId>jboss-persistence-api</artifactId>
<version>3.0.0-SNAPSHOT</version>
</dependency>

EJB3 :
<dependency>                          
<groupId>jboss</groupId>
<artifactId>jboss-ejb-api</artifactId>
<version>4.2.0.GA</version>
</dependency>

That is all ! Complete pom.xml looks like this :
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0
http://maven.apache.org/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.mycompany.beans</groupId>
<artifactId>SimpleEJB3</artifactId>
<packaging>jar</packaging>
<version>1.0-SNAPSHOT</version>
<name>SimpleEJB3</name>
<url>http://maven.apache.org</url>
<parent>
<groupId>jboss</groupId>
<artifactId>jboss-parent</artifactId>
<version>2</version>
</parent>
<repositories>
<repository>
<id>jboss-maven2</id>
<url>http://repository.jboss.com/maven2</url>
</repository>
</repositories>

<dependencies>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>3.8.1</version>
<scope>test</scope>
</dependency>

<dependency>
<groupId>jboss</groupId>
<artifactId>jboss-persistence-api</artifactId>
<version>3.0.0-SNAPSHOT</version>
</dependency>

<dependency>
<groupId>jboss</groupId>
<artifactId>jboss-ejb-api</artifactId>
<version>4.2.0.GA</version>
</dependency>
</dependencies>

</project>

If there is something wrong with this solution, or maybe you have some improvement, give me a sign.

UPD

Complete example with source code is here : http://code.google.com/p/ostas-blog-src/