老鬼的博客 来都来啦,那就随便看看吧~
liberty配置jndi数据源
发布于: 2019-11-03 更新于: 2019-11-25 分类于: Liberty 阅读次数: 

一:介绍

1
2
liberty配置jndi数据源,这里主要是配置了MSSQL的数据源,使用了在配置文件中使用 Ref 标记来配置,
一些通用的东西配置在了usr/shared/config和resource目录下。

二:配置文件介绍

2.1 创建/启动/停止server

2.2 jdni相关配置文件

2.2.1 描述
1
2
这里我创建的server是elearning,所以下面的说明都是根据elearning这个server来说的,
和其他自己创建的或者defaultServer一样。
2.2.2 介绍
名称 路径 描述
server.xml \wlp-javaee8-18.0.0.4\usr\servers
\elearning\server.xml
elearning的配置文件
dataSource.xml \wlp-javaee8-18.0.0.4\usr\servers
\elearning\dataSource.xml
elearning的数据源配置文件
connectionManagerRef.xml \wlp-javaee8-18.0.0.4\usr\shared
\config\connectionManagerRef.xml
数据源连接池的通用配置文件
containerAuthDataRef.xml \wlp-javaee8-18.0.0.4\usr\shared
\config\containerAuthDataRef.xml
数据库认证的通用配置文件
jdbcDriver.xml \wlp-javaee8-18.0.0.4\usr\shared
\config\jdbcDriver.xml
数据库驱动的通用配置文件
sqljdbc-4.0.0.jar \wlp-javaee8-18.0.0.4\usr\shared
\resources\sq;jdbc-4.0.0.jar
sqlserver的驱动包
2.2.3 相关xml文件

1574668943.png

  1. server.xml

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    <?xml version="1.0" encoding="UTF-8"?>
    <server description="new server">

    <!-- Enable features -->
    <featureManager>
    <feature>javaee-8.0</feature>
    </featureManager>

    <!-- This template enables security. To get the full use of all the capabilities, a keystore and user registry are required. -->

    <!-- For the keystore, default keys are generated and stored in a keystore. To provide the keystore password, generate an
    encoded password using bin/securityUtility encode and add it below in the password attribute of the keyStore element.
    Then uncomment the keyStore element. -->
    <!--
    <keyStore password=""/>
    -->

    <!--For a user registry configuration, configure your user registry. For example, configure a basic user registry using the
    basicRegistry element. Specify your own user name below in the name attribute of the user element. For the password,
    generate an encoded password using bin/securityUtility encode and add it in the password attribute of the user element.
    Then uncomment the user element. -->

    <!-- 引入dataSource数据源,如果您想要跳过找不到的包含文件,那么可以将 optional 属性设为 true: -->
    <include location="dataSource.xml"/>

    <basicRegistry id="basic" realm="BasicRealm">
    <!-- <user name="yourUserName" password="" /> -->
    </basicRegistry>

    <!-- To access this server from a remote client add a host attribute to the following element, e.g. host="*" -->
    <httpEndpoint id="defaultHttpEndpoint"
    httpPort="11080"
    httpsPort="9443" />

    <!-- Automatically expand WAR files and EAR files -->
    <applicationManager autoExpand="true"/>


    </server>
  2. dataSource.xml

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    <server> 
    <featureManager>
    <feature>jdbc-4.1</feature>
    </featureManager>
    <!-- 引用shared/config目录下的通用的配置文件 -->
    <include location="${shared.config.dir}/containerAuthDataRef.xml"/> <!-- 认证用户的配置文件 -->
    <include location="${shared.config.dir}/connectionManagerRef.xml"/> <!-- 数据库连接池的配置信息 -->
    <include location="${shared.config.dir}/jdbcDriver.xml"/> <!-- jdbc驱动的通用配置信息 -->

    <!-- sit mssql elearning -->
    <dataSource
    id="sit-elearning"
    containerAuthDataRef="sit-mssql"
    jdbcDriverRef="mssql-driver"
    connectionManagerRef="sit-connectionManager"
    jndiName="jdbc/elearning"
    type="javax.sql.ConnectionPoolDataSource">
    <properties serverName="sit" databaseName="businessplanner" portNumber="21433" />
    </dataSource>
    </server>
  3. containerAuthDataRef.xml

    1
    2
    3
    4
    5
    6
    7
    <server>
    <featureManager>
    <feature>jdbc-4.1</feature>
    </featureManager>
    <!-- sit sqlserver -->
    <authData user="sa" password="123456" id="sit-mssql"></authData>
    </server>
  4. connectionManagerRef.xml

    1
    2
    3
    4
    5
    6
    <server>
    <featureManager>
    <feature>jdbc-4.1</feature>
    </featureManager>
    <connectionManager id="sit-connectionManager" minPoolSize="1" numConnectionsPerThreadLocal="10"/>
    </server>
  5. jdbcDriver.xml

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    <server>
    <featureManager>
    <feature>jdbc-4.1</feature>
    </featureManager>

    <jdbcDriver id="mssql-driver" libraryRef="mssql-lib"/>
    <library id="mssql-lib">
    <file name="${shared.resource.dir}\sqljdbc-4.0.0.jar"/>
    </library>
    </server>

三:相关参考文档

3.1 官方

3.2 其他参考文档(原创)

*************感谢您的阅读*************