標籤:weblogic 遷移 java tomcat
第1個問題:
異常描述:VALIDATION PROBLEMS WERE FOUND problem: cvc-enumeration-valid: string value ‘3.0‘ is not a valid enumeration value for web-app-versionType in namespace http://java.sun.com/xml/ns/javaee:<null>
因為建立項目的時候用的是JAVAEE6,所以產生web.xml檔案的時候是這樣的:
[java] view plaincopy
- <web-app version="3.0"
- xmlns="http://java.sun.com/xml/ns/javaee"
- xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
- xsi:schemaLocation="http://java.sun.com/xml/ns/javaee
- http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd">
weblogic10.3.6並不支援web-app_3_0.xsd的定義。所以報錯了。
改為如下就ok了:
<web-app version="2.5" xmlns="http://java.sun.com/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd">
或者部署到weblogic 12。
第2個問題:
異常描述:
Caused by: weblogic.management.DeploymentException: [HTTP:101170]The servlet default is referenced in servlet-mapping *.js, but not defined in web.xml.
原因:用預設servlet處理靜態資源。
<servlet-mapping>
<servlet-name>default</servlet-name>
<url-pattern>*.js</url-pattern>
</servlet-mapping>
<servlet-mapping>
<servlet-name>default</servlet-name>
<url-pattern>*.css</url-pattern>
</servlet-mapping>
每個web容器都有一個預設servlet,在tomcat預設servlet的名字是:defalut。而在weblogic是:FileServlet。下面列出各容器的預設servlet的名字
Tomcat, Jetty, JBoss, and GlassFish 預設 Servlet的名字"default" WebLogic 預設 Servlet的名字 "FileServlet" ,WebSphere預設 Servlet的名字 "Simpledefault" 。
將上面的default改成FileServlet就可以了。
第3個問題:
異常描述:
Annotation-specified bean name ‘containerTransactionType.Factory‘ for bean class [com.sun.java.xml.ns.javaee.ContainerTransactionType$Factory] conflicts with existing, non-compatible bean definition of same name and class [com.sun.java.xml.ns.j2Ee.ContainerTransactionType$Factory]
原因:
mvc-dispatcher-servlet.xml裡有這樣一個配置,
<!-- 需要掃描的標註了@Controller的類 -->
<context:component-scan base-package="com">
<context:include-filter type="regex"
expression=".*.action.*" />
<!-- 這裡排除service,防止事務失效 -->
<context:exclude-filter type="annotation" expression="org.springframework.stereotype.Service"/>
</context:component-scan>
我的包名是com.公司名.模組名。由於weblogic的包裡也有以com開頭action結尾的包,spring把它的包也掃描了,並注入容器。出現了同名的bean。所以報錯。
解決方案, 將<context:component-scan base-package="com">中包名加一層, 改成: <context:component-scan base-package="com.公司名">。
第4個問題:
異常描述:
Caused by: java.lang.Throwable: Substituted for missing class org.springframework.beans.factory.BeanCreationException - Error creating bean with name ‘ditemAction‘: Injection of autowired depende
ncies failed; nested exception is org.springframework.beans.factory.BeanCreationException: Could not autowire field: private com.jfpal.riskmanage.item.service.IDitemService
這是在createing 控制器 ‘ditemAction’時出的錯。原因是無法注入屬性com.jfpal.riskmanage.item.service.IDitemService 。代碼肯定沒問題的,tomcat上運行正常。
經過分析,斷定spring沒掃描com.jfpal.riskmanage.item.service.IDitemService 所在的包。
然後查看web.xml,發現如下配置
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>classpath*:applicationContext*.xml</param-value>
</context-param>
將其改為
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>classpath:applicationContext.xml,classpath:applicationContext-myBatis.xml</param-value>
</context-param>
後面那個資料來源的配置。改後部署成功。原因是weblogic和tomcat解析<param-value>有點不一樣。
第5個問題:
訪問項目時出錯,報404,說找不到**/**/dwz.frag.xml。查看web.xml,沒有配置xml靜態資源的訪問,加上如下配置
<servlet-mapping>
<servlet-name>FileServlet</servlet-name>
<url-pattern>*.xml</url-pattern>
</servlet-mapping>
至此遷移成功。