SpringBoot部署到WAS上的問題小結

省略桃花。。。僅做記錄
採用WAS版本爲8.5.5.9,PS:此版本以下版本不能良好的支持Servlet3.0的註解功能,而SpringBoot完全取消了web.xml的配置,採用註解方式。
採用JDK1.6,PS:從1.8降到1.7再到1.6,前後花費長時間發現1.6版本比較穩定,WAS的支持比較好。
在開發過程中遇到的問題如下:
1)採用jdk1.8時,由於服務器版本WAS8.0.0.9的JDK版本爲1.6,出現部署後404的問題“WebSphere Application Server:Error 404: java.io.FileNotFoundException: SRVE0190E: File not found:”,起初以爲是WAS不能支持註解形式的Servlet調起Spring,在網上查詢解決方案得到:去掉SpringBootServletInitializer接口實現,重新加入web.xml方式。出現JDK版本問題,遂降低至jdk1.6,期間出現spring-boot-starter-tomcat版本由8降至7.0.59,此種方式可行;
2)但是採用web.xml方式完全背離了SpringBoot的本意,故重新找到一臺WAS8.5.5.9的機器進行SpringBootServletInitializer方式啓動,出現 com.ibm.ws.ecs.internal.scan.context.impl.ScannerContextImpl scanJAR unable to open input stream for resource org/apache/ibatis/javassist/SerializedProxy.class in archive WEB-INF/lib/mybatis-3.4.0.jar 的問題,查詢解決方案:https://github.com/mybatis/mybatis-3/issues/706#issuecomment-227731860 獲知:mybatis3.4.0下的此類與SpringBoot不兼容,改爲 3.4.1即可解決

<dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-web</artifactId>
            <exclusions>
                <exclusion>
                    <groupId>org.springframework.boot</groupId>
                    <artifactId>spring-boot-starter-tomcat</artifactId>
                </exclusion>
            </exclusions>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-tomcat</artifactId>
            <scope>provided</scope>
        </dependency>
        <dependency>
            <groupId>org.mybatis.spring.boot</groupId>
            <artifactId>mybatis-spring-boot-starter</artifactId>
            <version>${mybatis.spring.version}</version>
            <exclusions>
                <exclusion>
                    <groupId>org.mybatis</groupId>
                    <artifactId>mybatis</artifactId>
                </exclusion>
            </exclusions>
        </dependency>
        <dependency>
            <groupId>org.mybatis</groupId>
            <artifactId>mybatis</artifactId>
            <version>3.4.1</version>
        </dependency>

Mybatis版本兼容問題原因:mybatis-spring-boot-starter爲高人貢獻,其中有個類涉及到注入方式爲構造器方式注入,在Spring中採用@Autowired方式注入時,會得到多個注入類,導致錯誤,沒有明白爲何會採用構造器方式注入。springBoot提供了此種問題的解決方式:Consider marking one of the beans as @Primary, updating the consumer to accept multiple beans, or using @Qualifier to identify the bean that should be consumed。即採用@Primary註解在多個構造時選取特定的一個。而某高人修改了此類的構造器注入方式爲註解注入,也解決了這個問題。

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章