2014-03-12 25 views
0

相当新来的Java来自c#背景。org.springframework.jdbc.cannotgetjdbcconnectionexception禁用Rmi类加载器

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

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

的方法IM试图揭露是

@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); 

} 
+0

这是关于'禁用RMI类加载器',阻止人们阅读堆栈跟踪的其余部分?这事儿常常发生。 – EJP

回答

0

您的例外是嵌套的异常,因此它发生在您的应用程序,

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

因此,它说是有缺失的类,它可能是jdbc,请确保您有它在你的课堂路径中。

所以如果你有它,检查连接标准为你的DB

+0

刚刚检查了应用程序的pom.xml并在那里定义。你是否会在OS级而不是在Eclipse? – Ernie