Posts Tagged ‘Spring’
java.lang.IllegalArgumentException: Malformed \uxxxx encoding
The above error is cause by the baclslash “\” that use in Windows.
I demostrate the error in this simple example.
The example is going to get the File object that being instancial by Spring to do further process.
The java code is looks like this:
public static void main(String[] args) {
ApplicationContext context = new ClassPathXmlApplicationContext(
new String[] {
"classpath:/alfred/demo/spring/applicationContext.xml"
});
BeanFactory factory = (BeanFactory) context;
final String myFileBeanName = "myFile";
File file = (File) factory.getBean(myFileBeanName);
.....
}
....
}
The applicationContext.xml for Spring:
...
<bean id="myFile" class="java.io.File">
<constructor-arg>
<value>${file.path}</value>
</constructor-arg>
</bean>
...
In the properties file, the $file.path is defined as file.path=D:\data\test\my-spring-file.txt.
When I trying to run the java code, it returns me
Exception in thread "main" java.lang.IllegalArgumentException: Malformed \uxxxx encoding.
at java.util.Properties.loadConvert(Unknown Source)
at java.util.Properties.load(Unknown Source)
....
So, I change the $file.path to file.path=D:\\data\\test\\my-spring-file.txt, and its work fine to me!
The prefix “tx” for element “tx:advice” is not bound
Error:
The prefix “tx” for element “tx:advice” is not bound
Story:
I was updating my code, to add in DB data insertion into 1 of my action class.
hit the above error “The prefix “tx” for element “tx:advice” is not bound”
From the error message, i think its complaining the missing of to define the schema location.
So, I add the schema location, and restart the tomcat…. eh, same error again?!
OK, i did a google and found out that, I not only missed to define the schema location;
I also forget to defind the “tx” header. (something like “tablib” in jsp).
So, I add in the following line “xmlns:xsi=”http://www.w3.org/2001/XMLSchema-instance” and test again.
Wow, its working now!
Lessons Learned:
The root cause of this error is missing the “xmlns:tx” being defined in applicationContext.xml
Solution:
Final applicationContext.xml header:
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:jee="http://www.springframework.org/schema/jee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:tx="http://www.springframework.org/schema/tx"
xmlns:aop="http://www.springframework.org/schema/aop"
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"
>