title: org.springframework.jdbc.cannotgetjdbcconnectionexception Rmi class loader disabled
body: <p>Rather new to Java coming from a c# background.</p>
  
  <p>What I am trying to achieve is just to expose a method to jConsole via jmx and rim.</p>
  
  <p>When I run my service and open jConsole I can see the method there and all looks good, now the problem comes in when i try to run this method via the console. The error I get is  "Problem invoking helloWorld : java.rmi.UnmarshalException: Error unmarshaling return; nested exception is: java.lang.ClassNotFoundException: org.springframework.jdbc.CannotGetJdbcConnectionException (no security manager: RMI class loader disabled)".</p>
  
  <p>The method im trying to expose is </p>
  
  <pre><code>@ManagedOperation
  public int helloWorld() throws Exception {
  
      return jdbcTemplate.queryForInt(sql);
  }
  </code></pre>
  
  <p>Here is my applicationContext file</p>
  
  <pre><code>    &lt;!-- this bean must not be lazily initialized if the exporting is to happen --&gt;
  &lt;bean id="exporter" class="org.springframework.jmx.export.MBeanExporter" lazy-init="false"&gt;
      &lt;property name="assembler" ref="assembler" /&gt;
      &lt;property name="namingStrategy" ref="namingStrategy" /&gt;
      &lt;property name="autodetect" value="true" /&gt;
  &lt;/bean&gt;
  
  &lt;bean id="jmxAttributeSource" class="org.springframework.jmx.export.annotation.AnnotationJmxAttributeSource" /&gt;
  
  &lt;!-- will create management interface using annotation metadata --&gt;
  &lt;bean id="assembler" class="org.springframework.jmx.export.assembler.MetadataMBeanInfoAssembler"&gt;
      &lt;property name="attributeSource" ref="jmxAttributeSource" /&gt;
  &lt;/bean&gt;
  
  &lt;!-- will pick up the ObjectName from the annotation --&gt;
  &lt;bean id="namingStrategy" class="org.springframework.jmx.export.naming.MetadataNamingStrategy"&gt;
      &lt;property name="attributeSource" ref="jmxAttributeSource" /&gt;
  &lt;/bean&gt;
  
  &lt;context:component-scan base-package="com.bulks" /&gt;
  
  
  &lt;!-- enable annotations like @Autowired, which you also most likely need --&gt;
  &lt;context:annotation-config/&gt;
  
  &lt;bean class="com.bulksms.resources.HelloWorldResource"/&gt;
  
  &lt;!-- setup basic datasource --&gt;
  &lt;bean id="dataSource" class="org.springframework.jdbc.datasource.DriverManagerDataSource"&gt;
      &lt;property name="driverClassName" value="com.mysql.jdbc.Driver"&gt;&lt;/property&gt;
      &lt;property name="url" value="jdbc:mysql://localhost:3306/apu"&gt;&lt;/property&gt;
      &lt;property name="username" value="root"&gt;&lt;/property&gt;
      &lt;property name="password" value="password"&gt;&lt;/property&gt;  
  &lt;/bean&gt;
  
  &lt;!-- jdbcTemplate bean --&gt;
  &lt;bean id="jdbcTemplate" class="org.springframework.jdbc.core.JdbcTemplate"&gt;
      &lt;property name="dataSource" ref="dataSource"&gt;&lt;/property&gt;
  &lt;/bean&gt;
  </code></pre>
  
  <p>What am i missing so my method can be executed from the console?</p>
  
  <p>-----SOLUTION------
  So after hacking away at this for long i tried to put the sql part in its own method and then just call the method in the helloWorld method.... Low and behold!!!! SUCCESS!!!</p>
  
  <pre><code>public int helloWorld() throws Exception {
      setValueFromQuery();
      return value;
  }
  
  private void setValueFromQuery() {
      this.value = jdbcTemplate.queryForInt(sql); 
  
  }
  </code></pre>