第一次嘗試 Spring MVC程式, 在動手前已先看完 Spring in Action 2nd 以及 Spring in Action 3rd (Early access edition).
但啟動過程中卻不順利, 在此紀錄一下遇到的問題及解決方法.
Environment:
Windows 7 32bit
JDK 1.5.0.22
Tomcat 6.0.32
Spring 3.1.0.M1 (w/ webflow 2.3.0)
GWT 2.3.0
1 tomcat 啟動時遇到下列警告
WARNING: [SetPropertiesRule]{Server/Service/Engine/Host/Context} Setting property 'source' to 'org.eclipse.jst.jee.server:AppName' did not find a matching property.
雖然不是什麼大問題, 不過看了很討厭, 在這裡有答案
只要把 tomcat server 的 Server Options-> Publish module contexts to separate XML files 打勾即可.
2 初始化 listener 時遇到下列 Exception(這是因為GWT自帶的validation-api-1.0.0.GA.jar造成)
Exception sending context initialized event to listener instance of class org.springframework.web.context.ContextLoaderListener
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'org.springframework.validation.beanvalidation.LocalValidatorFactoryBean#0': Invocation of init method failed; nested exception is javax.validation.ValidationException: Unable to find a default provider
...
...
...
Caused by: javax.validation.ValidationException: Unable to find a default provider
可下載hibernate-validator處理(我下的版本為4.1.0.Final)
3. 因為2引發另一個 Exception
Exception sending context initialized event to listener instance of class org.springframework.web.context.ContextLoaderListener
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'org.springframework.validation.beanvalidation.LocalValidatorFactoryBean#0': Invocation of init method failed; nested exception is java.lang.NoClassDefFoundError: org/slf4j/LoggerFactory
...
...
...
Caused by: java.lang.NoClassDefFoundError: org/slf4j/LoggerFactory
這是因為hibernate Validator需要SLF4J的關係.
download slf4j-1.6.1.zip
下載完成後, 將slf4j-api-1.6.1.jar及slf4j-simple-1.6.1.jar解到 /WEB-INF/lib 下即可.
4. 因為3又引發一個 Exception
Exception sending context initialized event to listener instance of class org.springframework.web.context.ContextLoaderListener
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'org.springframework.validation.beanvalidation.LocalValidatorFactoryBean#0': Invocation of init method failed; nested exception is java.lang.NoClassDefFoundError: javax/xml/bind/JAXBException
...
...
...
Caused by: java.lang.NoClassDefFoundError: javax/xml/bind/JAXBException
這是因為hibernate-validator-4.1.0.Final是用 Java 1.6寫的, 似乎有個bug, 在Java 1.5的環境下會發生錯誤.
依據workaround, 請下載下面2個jar檔, 放入/WEB-INF/lib即可.
Download jaxb-api-2.1.jar
Download jaxb-impl-2.1.3.jar
至此終於順利啟動我的第一支 Spring 3程式.
在 /WEB-INF/lib 也額外放了下列 jar 檔. 順便紀錄一下.
aopalliance.jar
commons-logging-1.1.1.jar
jstl-api-1.2.jar
jstl-impl-1.2.jar
log4j-1.2.16.jar
cglib-nodep-2.2.2.jar
commons-fileupload-1.2.2.jar
commons-io-2.0.1.jar
沒有留言:
張貼留言