如何使数据库Bean成为托管属性

时间:2013-07-22 20:53:34

标签: database jsf-2 managed-property

如何将此另一个Java项目中的数据库类(作为依赖项添加到动态Web应用程序中)添加为托管属性?

import java.sql.Connection;
import org.h2.jdbcx.JdbcConnectionPool;
import java.sql.SQLException;
    public class Database
    {
    private JdbcConnectionPool poolMgr;

    public Database(String path, String user, String password, int connectionPoolSize) throws SQLException
        {
            // Creates connection pool
            poolMgr = JdbcConnectionPool.create(path, user, password);
            poolMgr.setMaxConnections(connectionPoolSize);
        }

        public Connection getConnection() throws SQLException
        {
            return poolMgr.getConnection();
        }
    }

package com.project1.bean;
import com.project2.db.Database;
@ManagedBean
@RequestScoped
public class InputBean implements Serializable
{
@ManagedProperty("#{database}")
    private Database database;
 //getters and setters
}

0 个答案:

没有答案