![](/img/trans.png)
[英]org.springframework.jdbc.CannotGetJdbcConnectionException
[英]org.springframework.jdbc.cannotgetjdbcconnectionexception Rmi class loader disabled
来自ac#背景的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);
}
您的异常是一个嵌套的异常,因此它发生在您的应用程序上,
java.lang.ClassNotFoundException: org.springframework.jdbc.CannotGetJdbcConnectionException
因此,它说有一个缺少的类,可能是jdbc
,请确保在类路径中有它。
因此,如果有,请检查与DB
的连接条件。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.