相当新来的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);
}
这是关于'禁用RMI类加载器',阻止人们阅读堆栈跟踪的其余部分?这事儿常常发生。 – EJP