title: Swing with Spring troubles
body: <p>I'm trying to use <code>@Autowired</code> statement in Swing application which locates in Spring Web MVC project. I just run it as Java aplication.</p>
  
  <pre><code>import javax.mail.MessagingException;
  import javax.swing.*;
  
  import org.springframework.beans.factory.annotation.Autowired;
  
  import net.babobka.blog.headHunter.Converter;
  
  import java.awt.*;
  import java.awt.event.ActionEvent;
  import java.awt.event.ActionListener;
  import java.io.IOException;
  import java.text.SimpleDateFormat;
  import java.util.ArrayList;
  import java.util.List;
  
  public class MainFrame implements ActionListener {
      @Autowired
      private Converter converter;    
      JFrame jfrm = new JFrame("Project backup system");
      JButton startButton = new JButton("Start"),
              stopButton = new JButton("Stop");
      JLabel statusLab = new JLabel();
      BackupThread bt;
  
      MainFrame() {
          int eur = (int) converter.getRate("EUR", "RUB");//This is MainFrame.java:29
          jfrm.setLayout(new FlowLayout());
          startButton.addActionListener(this);
          stopButton.addActionListener(this);
          jfrm.setSize(275, 100);
          jfrm.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
          jfrm.add(startButton);
          jfrm.add(stopButton);
          jfrm.add(statusLab);
          jfrm.setVisible(true);
      }...
  </code></pre>
  
  <p>But <code>NullPointerException</code> is all that I've got. What's wrong with wiring? 
  Full trace:</p>
  
  <pre><code>Exception in thread "AWT-EventQueue-0" java.lang.NullPointerException
      at net.babobka.blog.app.MainFrame.&lt;init&gt;(MainFrame.java:29)
      at net.babobka.blog.app.MainFrame$1.run(MainFrame.java:60)
      at java.awt.event.InvocationEvent.dispatch(InvocationEvent.java:251)
      at java.awt.EventQueue.dispatchEventImpl(EventQueue.java:727)
      at java.awt.EventQueue.access$200(EventQueue.java:103)
      at java.awt.EventQueue$3.run(EventQueue.java:688)
      at java.awt.EventQueue$3.run(EventQueue.java:686)
      at java.security.AccessController.doPrivileged(Native Method)
      at java.security.ProtectionDomain$1.doIntersectionPrivilege(ProtectionDomain.java:76)
      at java.awt.EventQueue.dispatchEvent(EventQueue.java:697)
      at java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:242)
      at java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:161)
      at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:150)
      at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:146)
      at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:138)
      at java.awt.EventDispatchThread.run(EventDispatchThread.java:91)
  </code></pre>
  
  <p><code>Converter</code> works in other classes, except for Swing apps.</p>
  
  <p>Root-context.xml:</p>
  
  <pre><code>&lt;?xml  version="1.0" encoding="UTF-8"?&gt;
  &lt;beans xmlns="http://www.springframework.org/schema/beans"
      xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:aop="http://www.springframework.org/schema/aop"
      xmlns:beans="http://www.springframework.org/schema/beans"
      xmlns:context="http://www.springframework.org/schema/context"
      xmlns:mvc="http://www.springframework.org/schema/mvc" xmlns:jee="http://www.springframework.org/schema/jee"
      xmlns:lang="http://www.springframework.org/schema/lang" xmlns:p="http://www.springframework.org/schema/p"
      xmlns:tx="http://www.springframework.org/schema/tx" xmlns:util="http://www.springframework.org/schema/util"
      xmlns:cache="http://www.springframework.org/schema/cache" xmlns:task="http://www.springframework.org/schema/task"
      xsi:schemaLocation="
      http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc-3.0.xsd
       http://www.springframework.org/schema/cache http://www.springframework.org/schema/cache/spring-cache.xsd
       http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd     
       http://www.springframework.org/schema/task  http://www.springframework.org/schema/task/spring-task-3.0.xsd
          http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop.xsd
          http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd
          http://www.springframework.org/schema/jee http://www.springframework.org/schema/jee/spring-jee.xsd
          http://www.springframework.org/schema/lang http://www.springframework.org/schema/lang/spring-lang.xsd
          http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx.xsd
          http://www.springframework.org/schema/util http://www.springframework.org/schema/util/spring-util.xsd"&gt;
  
  
  
      &lt;context:annotation-config /&gt;
  
  
      &lt;context:component-scan base-package="net.babobka.blog" /&gt;
      &lt;mvc:resources mapping="/resources/**" location="/resources/" /&gt;
      &lt;cache:annotation-driven /&gt;
  
      &lt;bean id="cacheManager" class="org.springframework.cache.support.SimpleCacheManager"&gt;
          &lt;property name="caches"&gt;
              &lt;set&gt;
                  &lt;bean
                      class="org.springframework.cache.concurrent.ConcurrentMapCacheFactoryBean"
                      p:name="template" /&gt;
                  &lt;bean
                      class="org.springframework.cache.concurrent.ConcurrentMapCacheFactoryBean"
                      p:name="commonStatistic" /&gt;
  
                  &lt;bean
                      class="org.springframework.cache.concurrent.ConcurrentMapCacheFactoryBean"
                      p:name="langStatistic" /&gt;
  
              &lt;/set&gt;
          &lt;/property&gt;
      &lt;/bean&gt;
  
      &lt;bean id="converter" class="net.babobka.blog.headHunter.Converter" /&gt;
  
      &lt;bean id="googleCharts" class="net.babobka.blog.charts.GoogleCharts" /&gt;
  
      &lt;bean id="sender" class="net.babobka.blog.backupper.Sender" /&gt;
  
      &lt;bean id="mainFrame" class="net.babobka.blog.app.MainFrame" /&gt;
  
  
      &lt;bean id="propertyConfigurer"
          class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer"
          p:location="/WEB-INF/db/jdbc.properties" /&gt;
  
      &lt;bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource"
          destroy-method="close" p:driverClassName="${jdbc.driverClassName}"
          p:url="${jdbc.databaseurl}" p:username="${jdbc.username}" p:password="${jdbc.password}" /&gt;
      &lt;bean id="sessionFactory"
          class="org.springframework.orm.hibernate3.LocalSessionFactoryBean"&gt;
          &lt;property name="dataSource" ref="dataSource" /&gt;
          &lt;property name="configLocation"&gt;
              &lt;value&gt;/WEB-INF/db/hibernate.cfg.xml&lt;/value&gt;
          &lt;/property&gt;
          &lt;property name="configurationClass"&gt;
              &lt;value&gt;org.hibernate.cfg.AnnotationConfiguration&lt;/value&gt;
          &lt;/property&gt;
          &lt;property name="hibernateProperties"&gt;
              &lt;props&gt;
                  &lt;prop key="hibernate.dialect"&gt;${jdbc.dialect}&lt;/prop&gt;
                  &lt;prop key="hibernate.show_sql"&gt;${jdbc.show_sql}&lt;/prop&gt;
                  &lt;prop key="hibernate.connection.useUnicode"&gt;true&lt;/prop&gt;
                  &lt;prop key="hibernate.connection.characterEncoding"&gt;UTF-8&lt;/prop&gt;
                  &lt;prop key="hibernate.connection.charSet"&gt;UTF-8&lt;/prop&gt;
              &lt;/props&gt;
          &lt;/property&gt;
      &lt;/bean&gt;
  
  
  
  
      &lt;bean id="transactionManager"
          class="org.springframework.orm.hibernate3.HibernateTransactionManager"&gt;
          &lt;property name="sessionFactory" ref="sessionFactory" /&gt;
      &lt;/bean&gt;
      &lt;mvc:annotation-driven /&gt;
      &lt;tx:annotation-driven /&gt;
      &lt;task:annotation-driven /&gt;
  
  
      &lt;bean id="Backupper" class="net.babobka.blog.backupper.Backupper"&gt;&lt;/bean&gt;
  
      &lt;bean id="OldDataRemoval" class="net.babobka.blog.termination.OldDataRemoval"&gt;&lt;/bean&gt;
  
      &lt;bean id="HeadHunterImport" class="net.babobka.blog.headHunter.HeadHunterImport"&gt;&lt;/bean&gt;
  
  
  
      &lt;bean id="urlForwardController"
          class="org.springframework.web.servlet.mvc.UrlFilenameViewController" /&gt;
  
      &lt;bean id="tilesConfigurer"
          class="org.springframework.web.servlet.view.tiles2.TilesConfigurer"&gt;
          &lt;property name="definitions"&gt;
              &lt;list&gt;
                  &lt;value&gt;/WEB-INF/tiles.xml&lt;/value&gt;
              &lt;/list&gt;
          &lt;/property&gt;
      &lt;/bean&gt;
  
      &lt;bean id="viewResolver"
          class="org.springframework.web.servlet.view.UrlBasedViewResolver"&gt;
          &lt;property name="viewClass"
              value="org.springframework.web.servlet.view.tiles2.TilesView" /&gt;
      &lt;/bean&gt;
  
      &lt;bean id="viewResolver1"
          class="org.springframework.web.servlet.view.ResourceBundleViewResolver"&gt;
          &lt;property name="order" value="1" /&gt;
          &lt;property name="basename" value="views" /&gt;
      &lt;/bean&gt;
  
  
  
  &lt;/beans&gt;
  </code></pre>