我做的一個web項目從tomcat遷移到weblogic遇到的問題

來源:互聯網
上載者:User

標籤: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
  1. <web-app version="3.0"   
  2.     xmlns="http://java.sun.com/xml/ns/javaee"   
  3.     xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"   
  4.     xsi:schemaLocation="http://java.sun.com/xml/ns/javaee   
  5.     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>

至此遷移成功。




聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.