JBoss高级配置

一,配置数据源
以配置MySQL数据库为例,{JBOSS_HOME}是Jboss4.0.2的安装目录
1,从{JBOSS_HOME}/docs/examples/jca下找到mysql-ds.xml,如果是MS SQL Server 就是mssql-ds.xml;
  如果是oracle,就是oracle-ds.xml
2, 修改mysql-ds.xml的jndi-name,connection-url,driver-class,user-name,password元素,下面是一个例子
<?xml version="1.0" encoding="UTF-8"?>
<!-- $Id: mysql-ds.xml,v 1.3.2.1 2004/12/01 11:46:00 schrouf Exp $ -->
<!--  Datasource config for MySQL using 3.0.9 available from:
http://www.mysql.com/downloads/api-jdbc-stable.html
-->
<datasources>
  <local-tx-datasource>
    <jndi-name>MySqlDS</jndi-name>
    <connection-url>jdbc:mysql://127.0.0.1:3306/scretary</connection-url>
    <driver-class>com.mysql.jdbc.Driver</driver-class>
    <user-name>root</user-name>
    <password>pass</password>
    <exception-sorter-class-name>org.jboss.resource.adapter.jdbc.vendor.MySQLExceptionSorter</exception-sorter-class-name>
    <!-- sql to call when connection is created
    <new-connection-sql>some arbitrary sql</new-connection-sql>
      -->
    <!-- sql to call on an existing pooled connection when it is obtained from pool
    <check-valid-connection-sql>some arbitrary sql</check-valid-connection-sql>
      -->

    <!-- corresponding type-mapping in the standardjbosscmp-jdbc.xml (optional) -->
    <metadata>
       <type-mapping>mySQL</type-mapping>
    </metadata>
  </local-tx-datasource>
</datasources>
3,把修改好的文件拷贝到{JBOSS_HOME}/server/default/deploy下,重启Jboss。
如果没有错误的话,启动过程会输出:
10:15:40,593 INFO  [WrapperDataSourceService] Bound connection factory for resource adapter for ConnectionManager 'jboss.jca:service=DataSourceBinding,name=MySqlDS to JNDI name 'java:MySqlDS'
打开控制台http://localhost:8080/jmx-console ,在jboss.jca下可以看到我们刚刚配置的数据源
name=MySqlDS,service=DataSourceBinding
name=MySqlDS,service=LocalTxCM
name=MySqlDS,service=ManagedConnectionFactory
name=MySqlDS,service=ManagedConnectionPool
4,通过Jndi名字“java:MySqlDS”就可以访问数据源了

 

  private   static   void  getDataSource()  ... {
  Context ctx 
= null;
  
try ...{
   ctx 
= new InitialContext();
  }
 catch (NamingException e) ...{
   
// TODO Auto-generated catch block
   log.error("InitialContext错误:" + e.getMessage());
   
return;
  }

  
try ...{
   Object obj 
= ctx.lookup(dsJndiName);
   ds 
= (DataSource) obj;
  }
 catch (Exception e) ...{
   log.error(
"查找DataSource的Jndi名" + dsJndiName + "错误:"
     
+ e.getMessage());
  }

  
return;
 }


二 配置JMS Topic和Queue

以配置一个叫testTopic的JMS Topic和testQueue的Jms Queue为例
1,打开{JBOSS_HOME}/server/default/deploy/jms/jbossmq-destinations-service.xml文件
在</server>前后增加下面的一段:

 

  < mbean  code ="org.jboss.mq.server.jmx.Topic"
  name
="jboss.mq.destination:service=Topic,name=testTopic" >
    
< depends  optional-attribute-name ="DestinationManager" > jboss.mq:service=DestinationManager </ depends >
    
< depends  optional-attribute-name ="SecurityManager" > jboss.mq:service=SecurityManager </ depends >
    
< attribute  name ="SecurityConf" >
      
< security >
        
< role  name ="guest"  read ="true"  write ="true" />
        
< role  name ="publisher"  read ="true"  write ="true"  create ="false" />
        
< role  name ="durpublisher"  read ="true"  write ="true"  create ="true" />
      
</ security >
    
</ attribute >
  
</ mbean >


上面的意思是配置一个叫testTopic的Topic。可以根据自己的需要修改这个名字,其他的不用修改。
配置Queue跟Topic类似,加入下面这段:

   < mbean  code ="org.jboss.mq.server.jmx.Queue"
  name
="jboss.mq.destination:service=Queue,name=testQueue" >
    
< depends  optional-attribute-name ="DestinationManager" > jboss.mq:service=DestinationManager </ depends >
    
< depends  optional-attribute-name ="SecurityManager" > jboss.mq:service=SecurityManager </ depends >
    
< attribute  name ="MessageCounterHistoryDayLimit" > -1 </ attribute >
    
< attribute  name ="SecurityConf" >
      
< security >
        
< role  name ="guest"  read ="true"  write ="true" />
        
< role  name ="publisher"  read ="true"  write ="true"  create ="false" />
        
< role  name ="noacc"  read ="false"  write ="false"  create ="false" />
      
</ security >
    
</ attribute >
  
</ mbean >


上面这段配置代码是配置一个叫testQueue的Queue,也可根据需要修改名字。
2,重新启动Jboss,如果没有错误可以看到
10:15:39,281 INFO  [testTopic] Bound to JNDI name: topic/testTopic
10:15:39,296 INFO  [testQueue] Bound to JNDI name: queue/testQueue

通过Jndi名字“java:topic/testTopic”和“java:queue/testQueue”就可以访问Topic和Queue对象了。

 

转载于:https://www.cnblogs.com/muyuge/archive/2009/07/15/6152697.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值