Spring Configuration creating two beans instead of one
<p>I'm writing a RESTful web service using Spring MVC, using Java Configuration.  My configuration file is below.  My issue is this -- I discovered that 2 instances of "myService" bean is being created, instead of just one instance.  I'm not sure why?  How can I adjust the configuration to create only one?</p>

<p>Can anyone point me in the right direction?  Thanks!</p>

<p>Here's my configuration class....</p>

<pre><code>@Configuration
public class MyConfig {

    @Bean(name = "dataSource")
    public DriverManagerDataSource getDataSource() {
        DriverManagerDataSource dataSource = new DriverManagerDataSource();
        // datasource set up    
        return dataSource;
    }

    @Autowired
    @Bean(name = "sessionFactory")
    public SessionFactory getSessionFactory(DriverManagerDataSource dataSource) {
        LocalSessionFactoryBuilder sessionBuilder = new LocalSessionFactoryBuilder(dataSource);
        sessionBuilder.scanPackages("com.mypackages");
        sessionBuilder.addProperties(getHibernateProperties());
        return sessionBuilder.buildSessionFactory();
    }

    private Properties getHibernateProperties() {
        Properties properties = new Properties();
        properties.put("hibernate.show_sql", "true");
        properties.put("hibernate.enable_lazy_load_no_trans", "true");
        properties.put("hibernate.id.new_generator_mappings", "true");
        return properties;
    }

    @Autowired
    @Bean(name = "transactionManager")
    public HibernateTransactionManager getTransactionManager(SessionFactory sessionFactory) {
        HibernateTransactionManager transactionManager = new HibernateTransactionManager(sessionFactory);    
        return transactionManager;
    }

    @Bean
    public MyMainBean MyMainBean() {
        MyMainBean bean = new MyMainBean();
        bean.setService(myService());
        bean.setValidator(myValidator());
        return bean;
    }

    @Bean(name = "myService")
    public MyService myService() {
        MyService s = new MyService();
        s.setDao1(myDao1());        
        s.setDao2(myDao2());
        s.setCopyUtil(copyUtil());
        return s;
    }

    @Bean
    public MyDao1 myDao1() {
        return new MyDao1();
    }

    @Bean
    public MyDao2 myDao2() {
        return new MyDao2();
    }

    @Bean
    public CopyUtil copyUtil() {
        return new CopyUtil();
    }

    @Bean
    public ReportValidator reportValidator() {
        ReportValidator validator = new ReportValidator();
        validator.setService(myService());      
        return validator;
    }

    @Bean 
    public XMLValidator xmlValidator() {
        XMLValidator validator = new XMLValidator();
        validator.setService(myService());
        return validator;
    }
}
</code></pre>