Posts Tagged ‘Spring’
MultiException[java.lang.RuntimeException: Error scanning file]
Case
I run a project with JSF 2 / PrimeFaces 5 (BTW: it rocks!) / Spring 4 / Jetty 9 / Java 8:
MultiException java.lang.RuntimeException: Error scanning file SummerBean.class, java.lang.RuntimeException: Error scanning entry .../SummerService.class from jar file:/.../spring-tier-1.0-SNAPSHOT.jar, java.lang.RuntimeException: Error scanning entry .../SummerServiceImpl.class from jar file:/.../spring-tier-1.0-SNAPSHOT.jar at org.eclipse.jetty.annotations.AnnotationConfiguration.scanForAnnotations(AnnotationConfiguration.java:530)
Explanation
The error occurs because of a conflict on the JARs of ASM.
Fix
You have to override Jetty’s dependencies to ASM.
In Maven’s POM, amend Jetty plugin to force ASM versions:
<plugin> <groupId>org.eclipse.jetty</groupId> <artifactId>jetty-maven-plugin</artifactId> <version>${jetty.version}</version> <dependencies> <dependency> <groupId>org.ow2.asm</groupId> <artifactId>asm</artifactId> <version>5.0.2</version> </dependency> <dependency> <groupId>org.ow2.asm</groupId> <artifactId>asm-commons</artifactId> <version>5.0.2</version> </dependency> </dependencies> <!-- ... --> </plugin>
Then it should work 😉
Retour sur Devoxx FR 2013
J’ai eu la chance d’assister a la derniere journee de DevoxxFR a Paris, le vendredi 29/03/2013, pour le compte de mon employeur StepInfo, sponsor de l’evenement. Voici quelques impressions en vrac
General
- C’est bien organise, il y a du monde, et excepte au moment du depart au niveau des vestiaires, il n’y a pas eu de gros souci de logistique.
- Les entreprises sponsors ont joue le jeu 😉
- Que ce soit au niveau des stands ou des conferences, la domination des Mac est ecrasante! Google a reussi a mettre en valeur ses ChromeBooks, mais j’ai vu peu de Windows et encore moins de Linux.
- J’ai pu assister a 4 conferences, toutes interessantes, mais d’un niveau heterogene, je reviens dessus plus en detail ci-dessous.
IDE Java : astuces de productivité pour le quotidien
La conference est animee par Xavier Hanin (@xavierhanin). Il y presente les trois IDE phares du monde Java: NetBeans, Eclipse et IntelliJ IDEA.
Maitrisant plutot bien IDEA, je n’ai pas appris de choses fondamentales sur mon IDE, si ce n’est le raccourci Ctrl+Shift+A
pour afficher les intentions. J’ai connu NetBeans a ses debuts (Forte puis Sun ONE), mais j’en ai totalement perdu la maitrise depuis des annees. Quant a Eclipse, il m’arrive de le lancer quelques fois par an pour des problematiques clients specifiques, mais je suis contraint d’avoir recours a la souris en quasi-permanence ; sous IDEA c’est tres rare.
Un “sondage” assez grossier des personnes dans la salle a donne des resultats interessants: ~15% des developpeurs presents utilisent NetBeans, ~25% IDEA et ~90/95% Eclipse.
Quick Start avec le Cloud Google
La conference est animee par Didier Girard de SFEIR et Alexis Moussine-Pouchkine de Google France. Les principaux outils de Google pour le cloud sont presentes, en prenant pour hypothese de creer une startup: une solution “a l’ancienne”, avec serveurs d’applications, gestion materielle etc. est avancee, avant de ceder la place a une solution entierement sur le cloud de Google.
En un mot: c’est tres convaincant.
Je regrette que le sujet n’ait pas ete elargi vers des solutions cloud alternatives, comme celle d’Amazon.
- Didier Girard:
- Sur twitter: @DidierGirard
- Sur Google+: +Didier
- Alexis Moussine-Pouchkine:
- Blog: http://alexismp.wordpress.com/
- Twitter: @alexismp
- Google+: +Alexis
The Spring Update: Looking at Spring 3.1, 3.2, and 4.0
La presentation est menee par Josh Long de SpringSource. On se rend compte tres rapidement que ne serait-ce que pour la qualite du show, nous les Francais (voire les Latins) nous sommes largement en dessous de la qualite des Anglo-Saxons.
Josh enonce ses concepts, donne des exemples, met l’eau a la bouche. Au bout de 50′ de conference, je n’ai plus qu’une envie: retourner coder avec les dernieres versions de Spring!
Parmi toutes les nouveautes, j’en retiens deux:
- l’
AnnotationConfigApplicationContext
, qui m’evitera de taper d’ecrire un bloc comme:<context:component-scan annotation-config="true" base-package="lalou.jonathan.beans"/>
- l’integration future des websockets d’HTML5 pour obeir a la norme JEE7 d’ici la fin de l’annee.
Ce dernier point m’interesse particulierement, en raison d’un projet sur lequel je travaille actuellement, et dont nombre de problemes seraient resolus par les websockets de JEE7. Theoriquement, et potentiellement, d’ici la fin de l’annee 2013, nous pourrions integrer une brique “Spring JEE7″ avec websocket au sein d’un WebSphere 8 (donc non JEE7-compliant), au lieu d’etre dependant dans la prochaine release du serveur d’applications d’IBM.
Josh:
- sur twitter: @starbuxman
- sur son blog: http://joshlong.com/
- Google+: +Josh
Entre HPC et big data: un case study sur la simulation du risque de contrepartie
C’est la conference dont j’ai vu le moins le rapport avec Devoxx, mais ayant passe 7 ans dans la finance de marche j’y ai trouve mon interet. En passant, j’y ai vu le seul PC sous Windows de toutes les conferences :-D.
Le theme de cette conference est: comment deporter une partie du calcul intensif de Monte-Carlo du CPU vers les GPU? Ces derniers ont une taille et une structure de memoire radicalement differente de celles des CPU (CPU+RAM pour etre plus precis). Les GPU permettent d’effectuer des masses de calcul en un temps bien plus faible (jusqu’a 99% de gain) qu’en architecture classique, moyennant une reecriture du code C en un autre langage adapte, par exemple OpenCL.
Les deux speakers, de Murex, sont Adrien Tay Pamart (visiblement pas tres a l’aise en mode geek) et Jonathan Lellouche pour la partie technique.
Durant les questions, l’existence de ponts Java vers OpenCL, comme JavaCL est evoquee. Il est dommage de ne pas avoir plus de temps pour creuser ce theme.
5 ans et 500 releases en 50 minutes !
La presentation est dirigee par Freddy Mallet et Olivier Gaudin de Sonar.
La demonstration est rudement bien faite. Les dirigeant de SonarSource retracent, dans un ordre plus ou moins chronologique, les problemes, ou les impediments a-t-on envie de dire, rencontres en 5 ans sur Sonar.
Quelques themes forts: le context switching est une plaie, on ne gere pas une entreprise commerciale avec des clients comme un simple projet open source, etc.
- Freddy:
- Sur twitter: @FreddyMallet
- Olivier:
- Sur twitter: @gaudol
En guise de conclusion
Devoxx a repondu aux attentes que j’avais en y entrant:
- une journee de formation intensive et motivante
- revoir des “anciennes tetes”
- echanger des cartes de visite
Qu’il me soit donc permis ici de remercier StepInfo pour m’avoir permis d’acceder a cette journee, ainsi que les organisateurs de Devoxx pour le travail qu’il ont accompli.
Vivement DevoxxFR 2014!
Unable to instantiate default tuplizer… java.lang.NoSuchMethodError: org.objectweb.asm.ClassWriter.
Case
On running a web application hosted on Jetty, I get the following stracktrace:
Nested in org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'sessionFactory' defined in ServletContext resource [/WEB-INF/classes/config/spring/beans/HibernateSessionFactory.xml]: Invocation of init method failed; nested exception is org.hibernate.HibernateException: Unable to instantiate default tuplizer [org.hibernate.tuple.entity.PojoEntityTuplizer]: java.lang.NoSuchMethodError: org.objectweb.asm.ClassWriter.<init>(I)V
Unlike what I immediatly thought at first glance, the problem is not induced by the Tuplizer ; the actual error is hidden at the bottom: java.lang.NoSuchMethodError: org.objectweb.asm.ClassWriter.
Here are some of the dependencies:
org.hsqldb:hsqldb:jar:2.2.8:compile org.springframework:spring:jar:2.5.6:compile org.hibernate:hibernate:jar:3.2.7.ga:compile javax.transaction:jta:jar:1.0.1B:compile | +- asm:asm-attrs:jar:1.5.3:compile | \- asm:asm:jar:1.5.3:compile
Fix
Main fix
The case is a classic problem of inherited depencencies. To fix it, you have to excluse ASM 1.5.3, and replace it with more recent version. In the pom.xml
, you would then have:
<properties> <spring.version>3.1.0.RELEASE</spring.version> <hibernate.version>3.2.7.ga</hibernate.version> <asm.version>3.1</asm.version> </properties> ... <dependency> <groupId>org.hibernate</groupId> <artifactId>hibernate</artifactId> <version>${hibernate.version}</version> <exclusions> <exclusion> <groupId>asm</groupId> <artifactId>asm</artifactId> </exclusion> <exclusion> <groupId>asm</groupId> <artifactId>asm-attrs</artifactId> </exclusion> </exclusions> </dependency> <dependency> <groupId>asm</groupId> <artifactId>asm</artifactId> <version>${asm.version}</version> </dependency>
Other improvements
I took the opportunity to upgrade Spring 2.5 to Spring 3.1 (cf the properties above).
Besides, I modified the *.hbm.xml files to use object types, rather than primary types, eg replacing:
<id name="jonathanId" type="long">
with:
<id name="jonathanId" type="java.lang.Long">
How to export Oracle DB content to DBUnit XML flatfiles?
Case
From an Agile and TDD viewpoint, performing uni tests on DAO is a requirement. Sometimes, instead of using DBUnit datasets “out of the box”, the developper need test on actual data. In the same vein, when a bug appears on production, isolating and reproducing the issue is a smart way to investigate, and, along the way, fix it.
Therefore, how to export actual data from Oracle DB (or even MySQL, Sybase, DB2, etc.) to a DBUnit dataset as a flat XML file?
Here is a Runtime Test I wrote on this subject:
Fix
Spring
Edit the following Spring context file, setting the login, password, etc.
<?xml version="1.0" encoding="UTF-8"?> <beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.5.xsd"> <!-- don't forget to write this, otherwise the application will miss the driver class name, and therfore the test will fail--> <bean id="driverClassForName" class="org.springframework.beans.factory.config.MethodInvokingFactoryBean"> <property name="targetClass" value="java.lang.Class"/> <property name="targetMethod" value="forName"/> <property name="arguments"> <list> <value>oracle.jdbc.driver.OracleDriver</value> </list> </property> </bean> <bean id="connexion" class="org.springframework.beans.factory.config.MethodInvokingFactoryBean" depends-on="driverClassForName"> <property name="targetClass" value="java.sql.DriverManager"/> <property name="targetMethod" value="getConnection"/> <property name="arguments"> <list> <value>jdbc:oracle:thin:@host:1234:SCHEMA</value> <value>myLogin</value> <value>myPassword</value> </list> </property> </bean> <bean id="databaseConnection" class="org.dbunit.database.DatabaseConnection"> <constructor-arg ref="connexion"/> </bean> <bean id="queryDataSet" class="org.dbunit.database.QueryDataSet"> <constructor-arg ref="databaseConnection"/> </bean> </beans>
The bean driverClassForName
does not look to be used ; anyway, if Class.forName("oracle.jdbc.driver.OracleDriver")
is not called, then the test will raise an exception.
To ensure driverClassForName
is created before the bean connexion, I added a attribute depends-on="driverClassForName"
. The other beans will be created after connexion
, since Spring will deduce the needed order of creation via the explicit dependency tree.
Java
public class Oracle2DBUnitExtractor extends TestCase { private QueryDataSet queryDataSet; @Before public void setUp() throws Exception { final ApplicationContext applicationContext; applicationContext = new ClassPathXmlApplicationContext( "lalou/jonathan/Oracle2DBUnitExtractor-applicationContext.xml"); assertNotNull(applicationContext); queryDataSet = (QueryDataSet) applicationContext.getBean("queryDataSet"); } @Test public void testExportTablesInFile() throws DataSetException, IOException { // add all the needed tables ; take care to write them in the right order, so that you don't happen to fall on dependencies issues, such as ones related to foreign keys queryDataSet.addTable("MYTABLE"); queryDataSet.addTable("MYOTHERTABLE"); queryDataSet.addTable("YETANOTHERTABLE"); // Destination XML file into which data needs to be extracted FlatXmlDataSet.write(queryDataSet, new FileOutputStream("myProject/src/test/runtime/lalou/jonathan/output-dataset.xml")); } }
Spring / Mule / CheckExclusiveAttributesException: The attributes of Element … do not match the exclusive groups …
Case
I have the following block in my Mule config file:
<servlet:inbound-endpoint path="authenticationService" address="http://localhost:1234">
. Even though this block matches XSD constraints, it is illegal from a functionnal point of view.
I get the following stacktrace:
Offending resource: mule-config.xml; nested exception is org.springframework.beans.factory.BeanDefinitionStoreException: Unexpected exception parsing XML document from class path resource [lalou/jonathan/mule-config.xml]; nested exception is org.mule.config.spring.parsers.processors.CheckExclusiveAttributes$CheckExclusiveAttributesException: The attributes of Element servlet:inbound-endpoint{address=http://localhost:1234, name=.authenticationService:inbound.157:inbound-endpoint.158, path=authenticationService} do not match the exclusive groups [address] [ref] [path]
Explanation and Fix
The exception is meaningful: for the tag <servlet:inbound-endpoint
>, only one among the three following attributes is needed: path, ref and address.
To fix the issue, keep only the relevant attribute.