Saturday, April 26, 2014

Resolve TransactionManager lookup fails on JBoss EAP 6 (AS7): No JTA TransactionManager found at fallback JNDI location (NameNotFoundException)

Using JBoss EAP 6.2, I have an application running on it. I needed to exclude the JBoss Logging as explained in this link.
So adding the exclusion in the jboss-deployment-structure.xml I have errors.

 javax.naming.NameNotFoundException: TransactionManager -- service jboss.naming.context.java.module.myprojectname.TransactionManager
org.springframework.transaction.jta.JtaTransactionManager] No JTA TransactionManager found at fallback JNDI location [java:appserver/TransactionManager]
 javax.naming.NameNotFoundException: java:appserver/TransactionManager
javax.naming.NameNotFoundException: java:pm/TransactionManager

Oh oOh what happens. Ayyy. Jboss is angry because I have excluded its logging :|. Ok I will not use the Jboss logging even if it is not happy for that.
So now I need to fix the jndi lookup of the jboss transaction manager. If you look in Standalone.xml, you will not find this jndi name. Strange no !! In fact by default it is java:jboss/TransactionManager.

So all what I need now is to specify to Spring the name of my Transaction Manager. So first, I have removed the old declaration :


<tx:jta-transaction-manager/>

And I substitute it by : 


1
2
3
<bean id="transactionManager" class="org.springframework.transaction.jta.JtaTransactionManager">
       <property name="transactionManagerName" value="java:jboss/TransactionManager"/>
</bean>

And now every think is working and I can see in the log while deploying :

DEBUG org.springframework.transaction.jta.JtaTransactionManager  - Retrieving JTA TransactionManager from JNDI location [java:jboss/TransactionManager]

Thursday, April 24, 2014

Resolved : log4j:WARN No appenders could be found for logger (org.springframework.web.context.support.SpringBeanAutowiringSupport

I was fixing my Log4j.xml on my web project developed with Spring and running on JBoss.


Deploying my application, It catches my eyes an error message although my application was deployed.
it was this error:

4:27:14,323 ERROR [stderr] (MSC service thread 1-2) log4j:WARN No appenders could be found for logger (org.springframework.web.context.support.SpringBeanAutowiringSupport).
14:27:14,323 ERROR [stderr] (MSC service thread 1-2) log4j:WARN Please initialize the log4j system properly.

It was really strange as I declare a logger for org.springframework.
But it seems that the porblem is coming from SpringBeanAutowiringSupport. Although I have declared also a logger fro this method. It didn't work and I get the same error.

What is special for this class is that I am using it to extend my web service class an that it will be initialized and managed by Spring.
So my code was like this :

@WebService(serviceName = "UserService")
public class UserService extends SpringBeanAutowiringSupport {
// Here the service implementation
...
}

It was a normal code. And it works fine. But my log4j seems not very happy.
After some search, I have seen by chance in one blog how to use the SpringBeanAutowiringSupport differently.
Based on that, I have modified my code and now it looks like this :

@WebService(serviceName = "UserService")
public class UserService extends SpringBeanAutowiringSupport {

   @PostConstruct
    public void init() {
              SpringBeanAutowiringSupport.processInjectionBasedOnCurrentContext(this);
    }

...
}

Surprise, now every think is working nice and I have no more error messages while deploying.  This is nice :D

Surprise, When testing the Web service. I have a NullPointerException. So now I know that the Error comes from the extends. But to make my web service work, I need to use it.

Monday, April 21, 2014

Resolve Error: org/springframework/cglib/transform/impl/MemorySafeUndeclaredThrowableStrategy

I was working on a web application using Spring application.

When deploying my application on JBoss eap 6.2 Server, I got this Error :

Caused by: java.lang.NoClassDefFoundError: org/springframework/cglib/transform/impl/MemorySafeUndeclaredThrowableStrategy
at org.springframework.aop.framework.CglibAopProxy.getProxy(CglibAopProxy.java:187) [spring-aop-3.2.8.RELEASE.jar:3.2.8.RELEASE]
...
Caused by: java.lang.ClassNotFoundException: org.springframework.cglib.transform.impl.MemorySafeUndeclaredThrowableStrategy from [Module "deployment.dbm.war:main" from Service Module Loader]
at org.jboss.modules.ModuleClassLoader.findClass(ModuleClassLoader.java:197) [jboss-modules.jar:1.3.0.Final-redhat-2]

It was strange as I was using Spring Integration 3.0.2.RLEASE.

<dependency>
<groupId>org.springframework.integration</groupId>
<artifactId>spring-integration-core</artifactId>
<version> 3.0.2.RELEASE</version>
</dependency>

As I have then used the 4.0.0.M4 version of Spring-Integration. So I have decided to use it and once updated the web application was deploying with success.

<repositories>
<repository>
<id>spring-milestones</id>
<url>http://repo.springsource.org/libs-milestone/</url>
</repository>
</repositories>
<dependencies>
<dependency>
<groupId>org.springframework.integration</groupId>
<artifactId>spring-integration-core</artifactId>
<version>4.0.0.M4</version>
</dependency>

Sunday, April 20, 2014

Resolved : log4j:WARN No appenders could be found for logger (org.springframework.web.context.ContextLoader)

I was using log4j in one of my spring maven projects. although the log4j.xml were well done, I get a warning then an error during deployment :

Initializing Spring root WebApplicationContext
 [stderr] (ServerService Thread Pool -- 74) log4j:WARN No appenders could be found for logger (org.springframework.web.context.ContextLoader).
 ERROR [stderr] (ServerService Thread Pool -- 74) log4j:WARN Please initialize the log4j system properly.
 ERROR [stderr] (ServerService Thread Pool -- 74) log4j:WARN See http://logging.apache.org/log4j/1.2/faq.html#noconfig for more info.

My log4j.xml was under src/main/resources. bUT EVEN BY SPECIFYING THE log4jConfigLocation, didn't resolve the problem.
So my Web.xml were like this:





After some invetigation, I have found that we should add a Log4jConfigListener in the first line (with the log4jConfigLocation) :

<listener>
<listener-class>org.springframework.web.util.Log4jConfigListener</listener-class>
</listener>

So the Web.xml become:





Wasn't easy to find but at least now it is done :)

Thursday, April 17, 2014

Resolving Bash Error: syntax error near unexpected token `(' declare -a

Writing a bash script, I got an error when trying to run it :

syntax error near unexpected token `(' declare -a

My array was declared was :
declare -a persons = ('person1' 'person2')

Even though my code looks correct and nice ;) ,  Unix don't accept it. I was removing the quotes.... but nothing worked.

And finally I find the solution: In fact we shouldn't put any space between = and (.

declare -a persons=('person1' 'person2') 

Monday, April 14, 2014

Spring Integration: Mqtt integration and Transformation of the mqtt Message from CSV to Java Bean using int:transformer


Working with Spring Integration, the use of Mqtt become very easy. In fact we need only to declare an int-mqtt:message-driven-channel-adapter in the applicationContext or spring-integration-context.xml

The code is :



The integration graph looks then like this :

So in order to convert the message coming from the broker (in CSV format), we need to call the method convert in the created CsvConverter class. In order to configure this using int:transformer, we need to declare a spel-function where we specify the class and called method, then we use the Id inside the spEL expression inside the transformer by putting # before the id of the converter.
so here is the code.

<int:spel-function id="csvConverter" class="org.converter.CsvConverter" method="convert(java.lang.String)" />

<int:transformer id="csvTransformer"
input-channel="mqttMessages"
output-channel="record" expression="#csvConverter(payload)" />

So now the transformer will call the CSVConverter which will convert the mqtt message payload from CSV to Java Bean (here Record).  The conversion is done using CSVeed framework which construct the given bean from the csv message.




Articles les plus consultés