2012-03-10 4 views
1

유효한 데이터 소스 파일 (아래에 재현)이있는 서버에서 제대로 작동하는 로컬 데이터베이스에 연결할 수 있습니다. 나 또한 그들의 IP 주소가 다르다는 것을 제외하고는 똑같은 신임장을 가진 다른 기계를 가지고있다. 내 localhost DataSource 객체를 읽고 다른 ipaddress로 연결 URL을 업데이트하고 싶습니다. 어떻게해야합니까? 내 배포를 위해 JBoss 4.2.3을 사용하고 있습니다 (변경할 수 없음). 여기 JDBC 연결을위한 DataSource 객체의 URL을 업데이트합니다.

내가 여기
/** 
* This gets a DataSource for a specified IP address using pacsDS as a template. 
* @param ipaddress 
* @return 
*/ 
public static DataSource getDataSource(Context context, String ipaddress) throws NamingException { 
    DataSource ds = (DataSource)context.lookup("java:/pacsDS"); 
    // Update ds to make use of supplied ipaddress 
    // ... 
    return ds; 
} 

당신은 당신의 JBoss의 설정 파일을 매개 변수화 할 수있는 데이터 소스 XML 파일

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

<!-- ===================================================================== --> 
<!--                  --> 
<!-- JBoss Server Configuration           --> 
<!--                  --> 
<!-- ===================================================================== --> 

<!-- $Id: pacs-postgres-ds.xml 5174 2007-09-26 21:05:41Z gunterze $ --> 
<!-- ==================================================================== --> 
<!-- Datasource config for Postgres          --> 
<!-- ==================================================================== --> 


<datasources> 
    <local-tx-datasource> 
     <jndi-name>pacsDS</jndi-name> 
     <connection-url>jdbc:postgresql://localhost/pacsdb</connection-url> 
     <driver-class>org.postgresql.Driver</driver-class> 
     <user-name>postgres</user-name> 
     <password></password> 
     <!-- sql to call when connection is created. Can be anything, select 1 is valid for PostgreSQL 
     <new-connection-sql>select 1</new-connection-sql> 
     --> 

     <!-- sql to call on an existing pooled connection when it is obtained from pool. Can be anything, select 1 is valid for PostgreSQL 
     <check-valid-connection-sql>select 1</check-valid-connection-sql> 
     --> 

     <!-- corresponding type-mapping in the standardjbosscmp-jdbc.xml (optional) --> 
     <metadata> 
      <type-mapping>PostgreSQL 7.2</type-mapping> 
     </metadata> 
    </local-tx-datasource> 
</datasources> 

답변

0

입니다 생성하고자하는 방법이다.

https://community.jboss.org/wiki/SystemPropertiesInConfigFiles?_sscc=t

+0

당신은 나에게 당신이 코드에서 이러한 변수 중 하나를 업데이트 할 방법의 예를 줄 수 참조? 난 하드 디스크에 그것을 코드하는 방법을 참조하십시오,하지만 런타임에 그것을 변경해야합니다. – Jon

+0

xml 파일을 변경하여 jdbc : postgresql : // $ {connection.url}/pacsdb을 읽은 다음 코드에 System.setProperty ("연결. url ","localhost "); DataSource를 검색하기 전에는 작동하지 않는 것 같습니다. – Jon

+0

데이터 소스가 시작할 때로드됩니다. 명령 줄에서 속성을 설정해야합니다. 예 : -Dconnection.url =

관련 문제