2012-01-18 55 views
2

当部署在JRuby在Rails 3.1的应用程序到JBoss,我有一个JNDI/JDBC连接问题。数据源存在,并且连接细的Rails 3.1部署到JBoss 4.2.2

17:47:20,862 ERROR [STDERR] JNDI data source unavailable: javax.naming.NameNotFoundException: jdbc not bound; trying straight JDBC 
17:47:20,926 ERROR [org.apache.catalina.core.ContainerBase.[jboss.web].[localhost].[/MyApp]] unable to create shared application instance 
org.jruby.rack.RackInitializationException: jdbc adapter requires driver class and url 
    from C:/opt/jboss/jboss-4.2.2.GA-Virgin/server/default/tmp/deploy/tmp1619261931370223075MyApp-exp.war/WEB-INF/gems/gems/activerecord-jdbc-adapter-1.2.0/lib/arjdbc/jdbc/connection.rb:21:in `configure_connection' 
    from C:/opt/jboss/jboss-4.2.2.GA-Virgin/server/default/tmp/deploy/tmp1619261931370223075MyApp-exp.war/WEB-INF/gems/gems/activerecord-jdbc-adapter-1.2.0/lib/arjdbc/jdbc/connection.rb:84:in `initialize' 
    from C:/opt/jboss/jboss-4.2.2.GA-Virgin/server/default/tmp/deploy/tmp1619261931370223075MyApp-exp.war/WEB-INF/gems/gems/activerecord-jdbc-adapter-1.2.0/lib/arjdbc/jdbc/adapter.rb:32:in `initialize' 
    from C:/opt/jboss/jboss-4.2.2.GA-Virgin/server/default/tmp/deploy/tmp1619261931370223075MyApp-exp.war/WEB-INF/gems/gems/activerecord-jdbc-adapter-1.2.0/lib/arjdbc/jdbc/connection_methods.rb:6:in `jdbc_connection' 
    from org/jruby/RubyKernel.java:2097:in `send' 

...

Caused by: org.jruby.exceptions.RaiseException: (ConnectionNotEstablished) jdbc adapter requires driver class and url 
17:47:23,010 ERROR [org.apache.catalina.core.ContainerBase.[jboss.web].[localhost].[/MyApp]] Error: application initialization failed 
org.jruby.rack.RackInitializationException: unable to create shared application instance 
    at org.jruby.rack.SharedRackApplicationFactory.init(SharedRackApplicationFactory.java:39) 
    at org.jruby.rack.RackServletContextListener.contextInitialized(RackServletContextListener.java:45) 
    at org.apache.catalina.core.StandardContext.listenerStart(StandardContext.java:3856) 

的database.yml

############################################################### 
#################### PRODUCTION DATA ########################## 
############################################################### 

production: 
    adapter: jdbc 
    jndi: java:jdbc/my_datasource 
    driver: com.microsoft.sqlserver.jdbc.SQLServerDriver 

我检查了两个数据源和database.yml文件,但我有没有线索为什么Rails没有找到数据源。

更新

Warbler config 

# Disable Rake-environment-task framework detection by uncommenting/setting to false 
# Warbler.framework_detection = false 
# 
puts 'Compiling the asset manifests & other files in the pipeline to the disk' 
system('bundle exec rake RAILS_ENV=production RAILS_GROUPS=assets assets:precompile') 

# Warbler web application assembly configuration file 
Warbler::Config.new do |config| 

    # Application directories to be included in the webapp. 
    config.dirs = %w(app config lib log vendor tmp) 

    # Name of the archive (without the extension). Defaults to the basename 
    # of the project directory. 
    config.jar_name = "MyApp" 

    # Control the pool of Rails runtimes. Leaving unspecified means 
    # the pool will grow as needed to service requests. It is recommended 
    # that you fix these values when running a production server! 
    config.webxml.jruby.min.runtimes = 1 
    config.webxml.jruby.max.runtimes = 1 

    # JNDI data source name 
    # config.webxml.jndi = 'jdbc/rails' 
end 

DataSource配置

<datasources>  
<xa-datasource> 
    <jndi-name>jdbc/my_datasource</jndi-name> 
    <track-connection-by-tx/> 
    <isSameRM-override-value>false</isSameRM-override-value> 
    <xa-datasource-class>com.microsoft.sqlserver.jdbc.SQLServerXADataSource</xa-datasource-class> 
    <xa-datasource-property name="ServerName">myserver</xa-datasource-property> 
    <xa-datasource-property name="DatabaseName">mydb</xa-datasource-property> 
    <xa-datasource-property name="SelectMethod">cursor</xa-datasource-property> 
    <valid-connection-sql>SELECT 1</valid-connection-sql> 
    <user-name>user</user-name> 
    <password>pwd</password> 
     <metadata> 
     <type-mapping>MS SQLSERVER2000</type-mapping> 
     </metadata> 
    </xa-datasource> 
</datasources> 

回答

3

部署.war文件啁啾了Rails的3.0.x的/ JBoss的5.1.0GA时,以下为我的作品。

假设你已经成功地部署您的数据源与XML配置文件,它应该是这样的:

<?xml version="1.0" encoding="UTF-8"?> 
<datasources> 
    <local-tx-datasource> 
     <jndi-name>my_datasource</jndi-name> 
     <connection-url>MYDATASOURCE_URL</connection-url> 
     <driver-class>your.Driver</driver-class> 
     ... define any other connection properties here ... 
    </local-tx-datasource> 
</datasources> 

你应该确认你的数据源确实是启动并运行在JBoss的管理控制台。

然后,假设你有你的config/warble.rb文件中的以下内容:

# JNDI data source name 
config.webxml.jndi = 'jdbc/my_datasource' 

# JBoss web-xmle file 
config.includes = 'jboss-web.xml' 

...并进一步假设你有一个直接配置jboss-web.xml文件中为您的Rails项目文件夹下,有以下几点:

<jboss-web> 
    <resource-ref> 
     <res-ref-name>jdbc/my_datasource</res-ref-name> 
     <jndi-name>java:/my_datasource</jndi-name> 
     <res-type>javax.sql.DataSource</res-type> 
    </resource-ref> 
</jboss-web> 

...那么你应该确定,据我所知。

你能也许发表您的warble.rb,数据源XML配置文件,以及任何JBoss应用配置参数要设置?

[编辑] @Jared感谢您发布您的配置文件。关闭我的头顶,我可以为您提供建议的下列位:

  1. 纠正你database.ymljava:comp/env/jdbc/my_datasourcejndi值。
  2. 定义config.webxml.jndi配置在warble.rb,并将其设置为jdbc/my_datasource
  3. 此外,在您的warble.rb定义到一个新的JBoss web.xml文件的引用与config.includes = jboss-web.xml
  4. 创建这个新jboss-web.xml到JNDI名称映射到JBoss资源引用名。根据你分享的文件,这将是我上面显示的内容。你可以在你的Rails项目的根目录下创建这个文件。

希望这会有所帮助!

+0

我明天。 Lightbulb今晚继续,我意识到应用程序可能会在数据源之前加载。我的同事部署得很好,但我无法(新鲜的JBoss,没有其他应用程序)。 http://confluence.atlassian.com/display/CONF210/Known+Issues+for+JBoss – 2012-01-18 04:06:59

+0

增加了warble配置,数据源等 – 2012-01-18 17:28:55

2

我接受了buruzaemon的建议。结果发现我不小心将我的war文件复制到了/deploy/uuid-key-generator.sar目录,我在jboss堆栈跟踪显示错误的jruby-jar版本后才发现这个。

为了什么它的价值,我学会了添加依赖

<depends>jboss.jca:service=DataSourceBinding,name=mydatasource</depends> 

给力的数据源文件的加载所有的应用程序之前,

/jboss-web.deployer/META-INF/jboss-service.xml 
+0

感谢您分享数据源加载依赖关系上的位...很高兴知道! – buruzaemon 2012-01-19 03:22:16