简体   繁体   English

从OSGI bundle数据源调用

[英]Call from OSGI bundle Datasource

Following this tutorial http://netbeans.org/kb/docs/javaee/maven-osgiservice-cdi.html I have managed to create a simple OSGI bundle and a client web application. 按照本教程http://netbeans.org/kb/docs/javaee/maven-osgiservice-cdi.html,我设法创建了一个简单的OSGI包和一个客户端Web应用程序。 I placed a managed bean into the web application client. 我将托管bean放入Web应用程序客户端。 The managed been calls a interface placed into the OSGI bundle. 被管理者调用了放置在OSGI包中的接口。 I successfully compile the code. 我成功地编译了代码。 Now the interesting part is can I place a data into the OSGI bundle which can make queries to the database. 现在,有趣的部分是我可以将数据放入OSGI捆绑软件中,以便对数据库进行查询。 This is the code that I placed into the OSGI bundle: 这是我放入OSGI捆绑软件中的代码:

package com.test;

import javax.ejb.Remote;

/** include default packages for Beans */
import java.io.Serializable;
import javax.enterprise.context.SessionScoped;
   // or import javax.faces.bean.SessionScoped;
import javax.inject.Named;
/** include package for SHA-256 encryption */
import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;
/** include SQL Packages */
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import javax.sql.DataSource;
import javax.annotation.Resource;
   // or import javax.faces.bean.ManagedBean; 



@Remote
public interface SL_43Remote {

    @Resource(name="java:/Oracle")
    private DataSource ds;



}

Betbeans 7.1 shows error: "modifier private is not allowed" and "= expected". Betbeans 7.1显示错误:“不允许使用修饰符私有”和“ =预期”。 Maybe I'm missing some libraries or maybe OSGI bundles don't allow source code for working with databases. 也许我缺少一些库,或者OSGI捆绑软件不允许源代码用于数据库。 Any idea how to fix the problem? 任何想法如何解决该问题?

Kind Regards. 亲切的问候。 Peter 彼得

Private fields are not allowed on interfaces in Java. Java接口中不允许使用私有字段。

This problem has nothing to do with OSGi, just the fundamentals of Java. 这个问题与OSGi无关,只是Java的基础。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM