【问题标题】:org.springframework.jdbc.cannotgetjdbcconnectionexception Rmi class loader disabledorg.springframework.jdbc.cannotgetjdbcconnectionexception Rmi 类加载器已禁用
【发布时间】:2014-03-12 08:18:41
【问题描述】:

来自 c# 背景的 Java 新手。

我想要实现的只是通过 jmx 和 rim 向 jConsole 公开一个方法。

当我运行我的服务并打开 jConsole 时,我可以看到那里的方法并且一切看起来都很好,现在当我尝试通过控制台运行此方法时问题出现了。我得到的错误是“调用 helloWorld 的问题:java.rmi.UnmarshalException:解组返回错误;嵌套异常是:java.lang.ClassNotFoundException:org.springframework.jdbc.CannotGetJdbcConnectionException(无安全管理器:RMI 类加载器已禁用)”。

我试图公开的方法是

@ManagedOperation
public int helloWorld() throws Exception {

    return jdbcTemplate.queryForInt(sql);
}

这是我的 applicationContext 文件

    <!-- this bean must not be lazily initialized if the exporting is to happen -->
<bean id="exporter" class="org.springframework.jmx.export.MBeanExporter" lazy-init="false">
    <property name="assembler" ref="assembler" />
    <property name="namingStrategy" ref="namingStrategy" />
    <property name="autodetect" value="true" />
</bean>

<bean id="jmxAttributeSource" class="org.springframework.jmx.export.annotation.AnnotationJmxAttributeSource" />

<!-- will create management interface using annotation metadata -->
<bean id="assembler" class="org.springframework.jmx.export.assembler.MetadataMBeanInfoAssembler">
    <property name="attributeSource" ref="jmxAttributeSource" />
</bean>

<!-- will pick up the ObjectName from the annotation -->
<bean id="namingStrategy" class="org.springframework.jmx.export.naming.MetadataNamingStrategy">
    <property name="attributeSource" ref="jmxAttributeSource" />
</bean>

<context:component-scan base-package="com.bulks" />


<!-- enable annotations like @Autowired, which you also most likely need -->
<context:annotation-config/>

<bean class="com.bulksms.resources.HelloWorldResource"/>

<!-- setup basic datasource -->
<bean id="dataSource" class="org.springframework.jdbc.datasource.DriverManagerDataSource">
    <property name="driverClassName" value="com.mysql.jdbc.Driver"></property>
    <property name="url" value="jdbc:mysql://localhost:3306/apu"></property>
    <property name="username" value="root"></property>
    <property name="password" value="password"></property>  
</bean>

<!-- jdbcTemplate bean -->
<bean id="jdbcTemplate" class="org.springframework.jdbc.core.JdbcTemplate">
    <property name="dataSource" ref="dataSource"></property>
</bean>

我缺少什么以便可以从控制台执行我的方法?

-----解决方案------ 因此,在长时间解决这个问题后,我尝试将 sql 部分放在它自己的方法中,然后在 helloWorld 方法中调用该方法.... 低,看哪!!!!成功!!!

public int helloWorld() throws Exception {
    setValueFromQuery();
    return value;
}

private void setValueFromQuery() {
    this.value = jdbcTemplate.queryForInt(sql); 

}

【问题讨论】:

  • “RMI 类加载器已禁用”阻止人们阅读堆栈跟踪的其余部分是什么?这种情况一直在发生。

标签: java spring jdbc rmi jconsole


【解决方案1】:

你的异常是一个嵌套的异常,所以它发生在你的应用程序上,

java.lang.ClassNotFoundException: org.springframework.jdbc.CannotGetJdbcConnectionException

所以它说缺少一个类,可能是jdbc,确保你的类路径中有它。

所以如果你有它,检查你的DB的连接条件。

【讨论】:

  • 刚刚检查了应用程序的 pom.xml 并在那里定义了它。你认为它会在操作系统级别而不是在 Eclipse 中吗?
猜你喜欢
  • 1970-01-01
  • 2023-04-09
  • 1970-01-01
  • 1970-01-01
  • 2012-06-21
  • 2011-09-13
  • 1970-01-01
  • 1970-01-01
  • 2015-03-26
相关资源
最近更新 更多