備忘録 the next generation

2014年末にOCN(http://yamagu.mo-blog.jp)からこちらに移転しました。

Struts2.1のセットアップまで[2]

2009-08-10 17:57:04 | 開発

webapps/[myapp]/META-INFディレクトリを作る。
ここにcontext.xmlを置く。

内容は以下のようなもの。[myapp]はWebアプリケーション名で
[myname]はDBに接続するアカウント名。
以下の例ではDB名とWebアプリケーション名は同一のものにしている。
Realmのような記述をして、DB内の情報による認証に備える。
----
<?xml version="1.0" encoding="UTF-8"?>
<Context path="/[myapp]" docBase="[myapp]"
   debug="1" reloadable="true" crossContext="false">

    <Resource name="jdbc/[myapp]" auth="Container"
        type="javax.sql.DataSource" driverClassName="org.postgresql.Driver"
        url="jdbc:postgresql://localhost:5432/[myapp]"
        username="[myname]" password="" maxActive="20" maxIdle="10"
        maxWait="-1" removeAbandoned="true"/>

    <Realm className="org.apache.catalina.realm.DataSourceRealm" debug="100"
        localDataSource="true"
        dataSourceName="jdbc/[myapp]"
        userTable="tomcat_user" userNameCol="userid" userCredCol="password"
        userRoleTable="tomcat_role" roleNameCol="role" />
</Context>
----

確認すべきポイントは、
reloadable: Servletの自動リロードだろうから開発が完了したらfalseで良いかも
removeAbandoned: 使われていないDBのコネクションを自動的に破棄。
         できればfalseの方がいいんだけど。
userTable: ユーザー情報を格納したテーブル名。
userNameCol: そのユーザ名の入っているカラム名
userCredCol: パスワードの入っているカラム名
userToleTable: ロール(役割)の入っているカラム名
roleNameCol: ロール名の入っているカラム名


最新の画像もっと見る

コメントを投稿