1. 程式人生 > >springboot+mybatis+dorado整合

springboot+mybatis+dorado整合

springboot+mybatis+dorado整合

前面已經整合過springboot+mybatis,這裡實在已經整合好springboot+mybatis的基礎上整合dorado的,如果不會整合springboot+mybatis可以看看我之前的博文。

目錄

1.eclipse整合dorado外掛
2.下載整合dorado需要的依賴包
3.匯入依賴包
4.工程WEB-INF目錄下建立dorado-home目錄並配置
5.更新dorado規則

目錄說明:按照目錄上面的步驟順序做在過程中可以邊整合邊除錯。

1.eclipse整合dorado外掛

這個因為我使用的是公司提供的eclipse,eclipse已經整合好dorado外掛了,如果不會的可以百度一下eclipse如何整合dorado外掛。整合成功後在eclipse裡面建立新專案會有dorado專案。沒整合之前是不可以建立dorado專案的。特別說明我們可以建立單獨的dorado專案,單獨的springboot專案,單獨的maven專案。這裡旨在整合這些東西。

2.下載整合dorado需要的依賴包

依賴包目錄如下:
dorado-core.jar
dorado-skin-blue-sky.jar
dorado-skin-concise-red.jar
dorado-skin-daybreak.jar
cglib.jar
commons-beanutils.jar
commons-collections.jar
commons-jexl.jar
commons-lang.jar
ehcache-core.jar
jackson-core-asl.jar
jackson-mapper-asl.jar
javassist.jar
spring-context-support.jar

具體jar包的版本可以參考下圖:
這裡寫圖片描述
注意:這裡的springboot+mybatis工程的名稱和上次建立好的工程名稱不一樣,這裡使用的工程只是在名稱上修改了,其他的還是不變。也就是說只要你已經建立好一個springboot+mybatis的框架好後這裡的整合dorado就可以用你的框架去整合。

3.匯入依賴包
3.1新建lib目錄

在你下載好相關jar包後,在你的工程的根目錄也就是你的專案名右鍵新建一個資料夾,名稱為lib,把你下載好的jar包放在lib資料夾下如圖:
這裡寫圖片描述

3.2匯入依賴包

開啟你工程的pom.xm,在資料夾中吧剛剛建立好的依賴全部新增進去,下面貼出我的整個pom.xml內容,前面部分是整合springboot+mybatis的依賴包,後面部門有註解為整合dorado開始的地方下面的都是整合dorado需要的一些依賴包,這裡整合dorado的依賴包基本是最簡的。如下程式碼:
pom.xml

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>

    <groupId>cn.idatatech</groupId>
    <artifactId>springDorado</artifactId>
    <version>0.0.1-SNAPSHOT</version>
    <packaging>war</packaging>

    <name>springDorado</name>
    <description>合併spring+mybatis+dorado</description>

    <parent>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-parent</artifactId>
        <version>2.0.4.RELEASE</version>
        <relativePath/> <!-- lookup parent from repository -->
    </parent>

    <properties>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
        <project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
        <java.version>1.8</java.version>
    </properties>

    <dependencies>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-web</artifactId>
        </dependency>

        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-tomcat</artifactId>
            <scope>provided</scope>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-test</artifactId>
            <scope>test</scope>
        </dependency>

        <!-- 配置mybatis依賴包 -->
        <dependency>
            <groupId>org.mybatis.spring.boot</groupId>
            <artifactId>mybatis-spring-boot-starter</artifactId>
            <version>1.3.2</version>
        </dependency>

        <!-- 新增阿里巴巴資料來源依賴包 druid-->
        <dependency>
            <groupId>com.alibaba</groupId>
            <artifactId>druid</artifactId>
            <version>1.0.29</version>
        </dependency>

        <!-- 配置mysql驅動 -->
        <dependency>
            <groupId>com.mysql</groupId>
            <artifactId>mysql-connector-java-5.1.41-bin</artifactId>
            <version>5.1.41</version>
            <systemPath>${basedir}/lib/mysql-connector-java-5.1.41-bin.jar</systemPath>
            <scope>system</scope>
        </dependency>

        <!--配置支援jsp-->
        <dependency>
            <groupId>javax.servlet</groupId>
            <artifactId>javax.servlet-api</artifactId>
            <scope>provided</scope>
        </dependency>
        <!-- 引入jsp中jstl包的支援 -->
        <dependency>
              <groupId>javax.servlet</groupId>
              <artifactId>jstl</artifactId>
              <version>1.2</version>
        </dependency>
        <dependency>  
            <groupId>org.apache.tomcat.embed</groupId>  
            <artifactId>tomcat-embed-jasper</artifactId>  
        </dependency>

        <!-- 配置dom4j,對xml檔案解析支援 -->
        <!-- 也可以配置saxon解析,這裡主要用來解析mapper.xml檔案 -->
        <dependency>
            <groupId>dom4j</groupId>
            <artifactId>dom4j</artifactId>
            <version>1.6.1</version>
        </dependency>

        <!-- =================================配置dorado============================================= -->
        <!-- dorado 7 -->
        <dependency>
            <groupId>com.bstek.dorado</groupId>
            <artifactId>dorado-core</artifactId>
            <version>7.6.0-SNAPSHOT</version>
            <scope>system</scope>
            <systemPath>${basedir}/lib/dorado-core.jar</systemPath>
        </dependency>

        <!-- commons-lang3 常用工具類 -->
        <dependency>
            <groupId>org.apache.commons</groupId>
            <artifactId>commons-lang-2.6</artifactId>
            <version>2.6</version>
            <scope>system</scope>
            <systemPath>${basedir}/lib/commons-lang-2.6.jar</systemPath>
        </dependency>

        <!-- commons-jexl -->
        <dependency>
            <groupId>org.apache.commons</groupId>
            <artifactId>commons-jexl-2.1.1</artifactId>
            <version>2.1.1</version>
            <scope>system</scope>
            <systemPath>${basedir}/lib/commons-jexl-2.1.1.jar</systemPath>
        </dependency>

        <!-- commons-collections -->
        <dependency>
            <groupId>org.apache.commons</groupId>
            <artifactId>commons-collections-3.2.1</artifactId>
            <version>3.2.1</version>
            <scope>system</scope>
            <systemPath>${basedir}/lib/commons-collections-3.2.1.jar</systemPath>
        </dependency>

        <!-- spring-context-support -->
        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-context-support-3.2.0.RELEASE</artifactId>
            <version>3.2.0</version>
            <scope>system</scope>
            <systemPath>${basedir}/lib/spring-context-support-3.2.0.RELEASE.jar</systemPath>
        </dependency>

        <!-- javassist -->
        <dependency>
            <groupId>javassist</groupId>
            <artifactId>javassist-3.12.1.GA</artifactId>
            <version>3.12.1</version>
            <scope>system</scope>
            <systemPath>${basedir}/lib/javassist-3.12.1.GA.jar</systemPath>
        </dependency>

        <!-- ehcache-core -->
        <dependency>
            <groupId>net.sf.ehcache</groupId>
            <artifactId>ehcache-core-2.6.3</artifactId>
            <version>2.6.3</version>
            <scope>system</scope>
            <systemPath>${basedir}/lib/ehcache-core-2.6.3.jar</systemPath>
        </dependency>

        <!-- commons-beanutils面板依賴包 -->
        <dependency>
            <groupId>org.apache.commons</groupId>
            <artifactId>commons-beanutils-1.8.3</artifactId>
            <version>1.8.3</version>
            <scope>system</scope>
            <systemPath>${basedir}/lib/commons-beanutils-1.8.3.jar</systemPath>
        </dependency>

        <!-- dorado-skin-blue-sky面板依賴包 -->
        <dependency>
            <groupId>com.bstek.dorado</groupId>
            <artifactId>dorado-skin-blue-sky-1.0.31</artifactId>
            <version>1.0.31</version>
            <scope>system</scope>
            <systemPath>${basedir}/lib/dorado-skin-blue-sky-1.0.31.jar</systemPath>
        </dependency>

        <!-- dorado-skin-red面板依賴包 -->
        <dependency>
            <groupId>com.bstek.dorado</groupId>
            <artifactId>dorado-skin-concise-red-1.0.65</artifactId>
            <version>1.0.65</version>
            <scope>system</scope>
            <systemPath>${basedir}/lib/dorado-skin-concise-red-1.0.65.jar</systemPath>
        </dependency>

        <!-- dorado-skin-daybreak面板依賴包 -->
        <dependency>
            <groupId>com.bstek.dorado</groupId>
            <artifactId>dorado-skin-daybreak-1.0.35</artifactId>
            <version>1.0.35</version>
            <scope>system</scope>
            <systemPath>${basedir}/lib/dorado-skin-daybreak-1.0.35.jar</systemPath>
        </dependency>

        <!-- jackson-core-asl解析與序列化 -->
        <dependency>
            <groupId>com.fasterxml.jackson.core</groupId>
            <artifactId>jackson-core-asl-1.9.11</artifactId>
            <version>1.9.11</version>
            <scope>system</scope>
            <systemPath>${basedir}/lib/jackson-core-asl-1.9.11.jar</systemPath>
        </dependency>

        <!-- jackson-mapper -->
        <dependency>
            <groupId>com.fasterxml.jackson.map</groupId>
            <artifactId>jackson-mapper-asl-1.9.11</artifactId>
            <version>1.9.11</version>
            <scope>system</scope>
            <systemPath>${basedir}/lib/jackson-mapper-asl-1.9.11.jar</systemPath>
        </dependency>

        <!-- net.sf.cglib -->
        <dependency>
            <groupId>net.sf.cglib</groupId>
            <artifactId>cglib-2.2.2</artifactId>
            <version>2.2.2</version>
            <scope>system</scope>
            <systemPath>${basedir}/lib/cglib-2.2.2.jar</systemPath>
        </dependency>

    </dependencies>

    <build>
        <plugins>
            <plugin>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-maven-plugin</artifactId>
            </plugin>
        </plugins>
    </build>


</project>

配置好後右鍵工程,選擇maven->update project,這樣就更新完成你的maven依賴包了(可以到你工程下的maven dependencies目錄下看看剛剛匯入的那些jar包有沒有匯入進去)。

4.工程WEB-INF目錄下建立dorado-home目錄並配置

在工程的src/main/webapp的WEB-INF目錄下新建一個資料夾,命名為dorado-home.新增相關配置,最好不要這麼幹,我的做法是新建立一個dorado專案,然後把dorado專案的相同路徑下的dorado-home拷貝一份放在自己的WEB-INF目錄下。目錄結構如下圖:
這裡寫圖片描述
各個檔案程式碼如下:
app-context.xml

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
       xmlns:jee="http://www.springframework.org/schema/jee"
       xmlns:tx="http://www.springframework.org/schema/tx"
       xmlns:context="http://www.springframework.org/schema/context"
       xsi:schemaLocation="
            http://www.springframework.org/schema/beans
            http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
            http://www.springframework.org/schema/tx
            http://www.springframework.org/schema/tx/spring-tx-3.0.xsd
            http://www.springframework.org/schema/jee
            http://www.springframework.org/schema/jee/spring-jee-3.0.xsd
            http://www.springframework.org/schema/context
            http://www.springframework.org/schema/context/spring-context-3.0.xsd"
>
</beans>

components-context.xml

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
       xmlns:d="http://www.bstek.com/dorado/schema"
       xsi:schemaLocation="
           http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.0.xsd
           http://www.bstek.com/dorado/schema
           http://www.bstek.com/dorado/schema/spring-dorado-7.0.xsd"
>

</beans>

configure-debug.properties

view.clientSideCache.defaultMaxAge=0
core.classPathResourceReloadable=true

view.debugEnabled=true
view.showExceptionStackTrace=true
view.mergeJavaScript=false
view.mergeStyleSheet=false

view.useMinifiedJavaScript=false
view.useMinifiedStyleSheet=false
view.outputPrettyJson=true

core.supportsTempFile=false

configure.properties

core.runMode=debug

# encoding
view.javaScript.charset=utf-8
view.styleSheet.charset=utf-8

context.xml

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
       xmlns:d="http://www.bstek.com/dorado/schema"
       xsi:schemaLocation="
http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
http://www.bstek.com/dorado/schema http://www.bstek.com/dorado/schema/spring-dorado-7.0.xsd">
    <import resource="app-context.xml"/>
    <import resource="components-context.xml"/>

    <!-- 配置dorado模型檔案的路徑 -->
    <bean parent="dorado.dataConfigLoader">
        <property name="configLocation" value="classpath*:cn/idatatech/**/*.model.xml"/>
    </bean>

    <!-- 配置dorado檢視檔案的路徑 -->
    <bean parent="dorado.viewConfigFactoryRegister">
        <property name="viewNamePattern" value="**"/>
        <property name="viewConfigFactory">
            <bean parent="dorado.xmlViewConfigDefinitionFactory">
                <property name="pathPrefix" value="WEB-INF/views"/>
                <property name="pathSubfix" value=".view.xml"/>
            </bean>
        </property>
    </bean>

    <!-- ???-->
    <bean parent="dorado.packagesConfigLoader">
        <property name="configLocation" value="classpath*:WEB-INF/dorado-home/packages-config.xml"/>
    </bean>

</beans>

packages-config.xml

<?xml version="1.0" encoding="UTF-8"?>
<config>
    <Patterns>
        <Pattern name="js" contentType="text/javascript" charset="UTF-8"
            mergeRequests='${configure["view.mergeJavaScript"]}' resourceSuffix=".js" />
        <Pattern name="css" contentType="text/css" charset="UTF-8"
            mergeRequests='${configure["view.mergeStyleSheet"]}' resourceSuffix=".css" />
        <Pattern name="res-js" contentType="text/javascript" charset="UTF-8"
                 mergeRequests="false" resourceSuffix=".js"
                 baseUri=">dorado/client/resources"/>
        <Pattern name="res-css" contentType="text/css" charset="UTF-8"
                 mergeRequests="false" resourceSuffix=".css"
                 baseUri=">dorado/client/resources"/>
    </Patterns>

    <Packages>
        <Package name="common" pattern="js"></Package>
    </Packages>
</config>

servlet-context.xml

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
       xmlns:jee="http://www.springframework.org/schema/jee"
       xmlns:tx="http://www.springframework.org/schema/tx" xmlns:context="http://www.springframework.org/schema/context"
       xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-3.0.xsd http://www.springframework.org/schema/jee http://www.springframework.org/schema/jee/spring-jee-3.0.xsd http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.0.xsd">
</beans>

w3c-html4-template.html

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
    <meta http-equiv="X-UA-Compatible" content="IE=Edge,chrome=IE8"/>
    #outputPageHeader()
</head>
<body style="margin:0; overflow:hidden">
<div id="doradoView" style="display:none"></div>
#outputPageFooter()
#outputException()
</body>
</html>

ok,到這裡就可以更新dorado規則了,這行第5步。

5.更新dorado規則

右鍵專案名,選擇更新dorado規則(如果沒有整合dorado外掛,這裡就沒有這個選項),過一會會提示更新dorado規則成功或者失敗。如果更新成功,那麼恭喜你已經完成springboot+mybatis+dorado框架的整合了,如果更新失敗。這時候多半是因為匯入依賴包的問題。仔細檢視控制檯列印的日誌資訊,看看是不是依賴包沒有導進去(如果沒有倒進依賴包,在進行maven->update project的時候你的pom.xml就會報錯),如果提示找不到某些包下的類,那個你可以參照一個dorado專案的lib資料夾下的jar包,看看報錯的找不到的那個類的包的名稱在不在dorado專案的lib資料夾下(正常都有,我就是這麼幹的),把這個包拷貝到你的springboot專案的lib資料夾下,然後在pom.xml新增該包的依賴(新增過程可以仿照前面的依賴新增)。

注:如何建立一個dorado檢視後成功訪問將在後面繼續,這裡先記錄到這裡。上面的整合知識可以更新dorado配置規則,但是訪問到dorado檢視還沒有配置。