2013-07-02 39 views
1

我有一個基本的ESB保險絲測試項目設置與以下模塊:ESB保險絲模塊等的依賴 - 寬限期

簡單的數據源 簡單的模型 簡單服務

的數據源配置通過藍圖和數據源連接到JNDI:

<?xml version="1.0" encoding="UTF-8"?> 

http://www.osgi.org/xmlns/blueprint/v1.0.0 http://www.osgi.org/xmlns/blueprint/v1.0.0/blueprint.xsd「>

<bean id="simpleDataSource" class="org.apache.commons.dbcp.BasicDataSource"> 
    <property name="driverClassName" value="oracle.jdbc.driver.OracleDriver" /> 
    <property name="url" value="jdbc:oracle:thin:@(DESCRIPTION=(LOAD_BALANCE=yes)(CONNECT_DATA=(SERVICE_NAME=xyz))(ADDRESS=(PROTOCOL=TCP)(HOST=xx.xx.xx.xx)(PORT=1521)))" /> 
    <property name="username" value="username" /> 
    <property name="password" value="password" />  
</bean> 

<!--bean id="simpleDataSource" class="oracle.jdbc.driver.OracleDriver">  
    <property name="URL" value="jdbc:oracle:thin:@(DESCRIPTION=(LOAD_BALANCE=yes)(CONNECT_DATA=(SERVICE_NAME=devd))(ADDRESS=(PROTOCOL=TCP)(HOST=10.75.192.195)(PORT=1521)))"/> 
    <property name="username" value="username" /> 
    <property name="password" value="password" />  
</bean--> 

<service ref="simpleDataSource" interface="javax.sql.DataSource"> 
    <service-properties> 
     <entry key="osgi.jndi.service.name" value="jdbc/simpleDataSource" /> 
    </service-properties> 
</service> 

該模型定義persistence.xml文件和參考文獻內的持久性單元通過JNDI數據源(注意此處所限定的長和短的JNDI查找,這兩者我都試過):

<persistence xmlns="http://java.sun.com/xml/ns/persistence" 
version="2.0"> 

<persistence-unit name="simple-service-persistence-unit" transaction-type="JTA"> 
    <provider>org.apache.openjpa.persistence.PersistenceProviderImpl</provider> 
    <!--jta-data-source>osgi:service/javax.sql.DataSource/(osgi.jndi.service.name=jdbc/simpleDataSource)</jta-data-source--> 
    <jta-data-source>osgi.jndi.service.name=jdbc/simpleDataSource</jta-data-source> 
    <!-- list of the persistance classes --> 
    <class>com.model.SimpleRow</class> 
    <exclude-unlisted-classes>true</exclude-unlisted-classes> 
</persistence-unit> 

的SimpleRow類使用JPA註解:

package com.model; 

import javax.persistence.Column; import javax.persistence.Entity; import javax.persistence.Table;

@Entity @Table(名稱= 「簡單」) 公共類SimpleRow {

@Column(name = "simple_id") 
private Long simpleId; 

@Column(name = "simple_text", length =100) 
private String simpleText; 

public Long getSimpleId() { 
    return simpleId; 
} 

public void setSimpleId(Long simpleId) { 
    this.simpleId = simpleId; 
} 

public String getSimpleText() { 
    return simpleText; 
} 

public void setSimpleText(String simpleText) { 
    this.simpleText = simpleText; 
} 

}

然後我嘗試了EntityManager注入一個服務,再次使用藍圖和參考到簡單服務的持久性單元:

<?xml version="1.0" encoding="UTF-8"?> 

http://www.osgi.org/xmlns/blueprint/v1.0.0 http://www.osgi.org/xmlns/blueprint/v1.0.0/blueprint.xsd http://aries.apache.org/xmlns/jpa/v1.1.0http://aries.apache.org/schemas/jpa/jpa_110.xsd「>

<bean id="simpleService" class="com.service.SimpleServiceImpl"> 
    <jpa:context property="entityManager" unitname="simple-service-persistence-unit" /> 
    <tx:transaction method="*" value="Required" /> 
</bean> 

<service ref="simpleService" interface="com.service.SimpleService" /> 

現在,當我安裝這些模塊到熔絲OSGi容器的簡單DataSource和簡單模塊兩者都顯示爲正確安裝。清單這些模塊給出:

[ 274] [Active  ] [   ] [  ] [ 60] Simple Model (1.0.0) 
[ 275] [Active  ] [Created  ] [  ] [ 60] Simple Datasource (1.0.0) 

我創建了使用注入的DataSource測試JDBC模塊和該確認數據源工作正常例如

public class DbExample { 
DataSource dataSource; 

public void setDataSource(DataSource dataSource) { 
    this.dataSource = dataSource; 
} 

public void test() throws Exception { 
    Connection con = dataSource.getConnection(); 
    Statement stmt = null; 
    DatabaseMetaData dbMeta = con.getMetaData(); 
    .... 
} 

現在,當我嘗試並啓動簡單服務時,它進入一個寬限期狀態和下面的消息被打印到日誌文件:

2013-07-02 11:05:33,772 | INFO | e-1.0.0-thread-1 | BlueprintContainerImpl   | ?         ? | 8 - org.apache.aries.blueprint.core - 1.0.1.fuse-71-047 | Bundle simple-service is waiting for dependencies [(&(&(org.apache.aries.jpa.proxy.factory=true)(osgi.unit.name=simple-service-persistence-unit))(objectClass=javax.persistence.EntityManagerFactory))] 

清單模塊狀態顯示它處於寬限期狀態:

[ 277] [Active  ] [GracePeriod ] [  ] [ 60] Simple Service Bundle (1.0.0) 

它最終超時並進入故障狀態。

現在我最初的想法是它可能是一個破損的數據源,但jdbc模塊證明它工作正常。我後來的想法是,jndi查找工作不正常,雖然我不知道如何檢查。有什麼方法可以查看jndi註冊表嗎?歡迎任何其他建議。

+0

'ls 275'顯示什麼? – vikingsteve

回答

1

您的軟件包正在等待顯示的服務,這可能是一個問題,因爲您引用的服務不可用(打開DEBUG登錄,您會看到日誌中的詳細信息)或有時會發生什麼情況(取決於Karaf/Aries的底層版本),您需要將藍圖切換爲使用同步部署,因爲有時等待的捆綁包無法捕獲後來啓動的服務。爲此,您需要翻轉etc/config.properties文件中的org.apache.aries.blueprint.synchronous = true

+0

梳理完日誌後,我發現簡單服務模塊正在等待事務功能。這是作爲INFO消息進一步報告日誌的,所以它最初並沒有引起我的注意。 – Ellis