【发布时间】: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