title: declare bean with @Bean in spring boot application
body: <p>I am just getting started with Spring (Boot).</p>
  
  <p>I have my "main" class in <code>abc.de</code>, annotated with <code>@SpringApplication</code>.</p>
  
  <p>So far, everything works fine. I have only used stereotype annotations.</p>
  
  <p>Now I would like to use <code>@Bean</code> with an <code>@Configuration</code> class, just to see how it works.</p>
  
  <p>My <code>@Configuration</code> class:</p>
  
  <pre><code>@Configuration
  public class BeanConfiguration {
  
      @Bean
      public XslDataFileLoader dataSource() {
          return new XslDataFileLoader();
      }
  }
  </code></pre>
  
  <p>The class <code>XslDataFileLoader</code> is in the same package.</p>
  
  <p>I declare this bean with <code>@Autowired</code> in a controller class.</p>
  
  <p>So my "main" class is in <code>abc.de</code>, the config class is in <code>abc.de.config</code> and the XslDataFileLoader is in <code>abc.de.config</code> as well.</p>
  
  <p>When I start the application, spring cannot inject the bean. It doesn't find it.</p>
  
  <p>I tried <code>scanPackages = abc.de.config</code>: That way, none of my other beans are found.</p>
  
  <p>How do I need to declare this in the latest spring boot?</p>
  
  <p><strong>EDIT</strong></p>
  
  <p><em>Stacktrace:</em></p>
  
  <pre><code>2017-05-19 13:52:03 ERROR o.s.b.d.LoggingFailureAnalysisReporter - 
  
  ***************************
  APPLICATION FAILED TO START
  ***************************
  
  Description:
  
  Field dataSource in abc.de.controllers.LoginController required a bean of type 'abc.de.config.XslDataFileLoader' that could not be found.
  
  
  Action:
  
  Consider defining a bean of type 'abc.de.config.XslDataFileLoader' in your configuration.
  </code></pre>
  
  <p><em>XslDataFileLoader:</em></p>
  
  <pre><code>package abc.de.config;
  
  public class XslDataFileLoader {
      public XslDataFileLoader() {
  
      }
  }
  </code></pre>
  
  <p><em>LoginController:</em></p>
  
  <pre><code>package abc.de.controllers;
  
  import org.springframework.beans.factory.annotation.Autowired;
  import org.springframework.stereotype.Controller;
  import org.springframework.web.bind.annotation.GetMapping;
  import org.springframework.web.bind.annotation.PostMapping;
  
  import abc.de.config.XslDataFileLoader;
  
  @Controller
  public class LoginController {
  
      @Autowired
      XslDataFileLoader loader;
  
      @GetMapping("/login")
      public String login() {
          System.out.println(loader);
          return "login";
      }
  
      @PostMapping("/login")
      public String loginTry() {
          return "redirect:dashboard";
      }
  }
  </code></pre>
  
  <p><strong>2ND EDIT</strong></p>
  
  <p><em>MySpringBootApplication:</em></p>
  
  <pre><code>package abc.de;
  
  import org.springframework.boot.SpringApplication;
  import org.springframework.boot.autoconfigure.SpringBootApplication;
  import org.springframework.data.jpa.repository.config.EnableJpaRepositories;
  
  @SpringBootApplication
  @EnableJpaRepositories
  public class MySpringBootApplication{
  
      public static void main(final String[] args) {
          SpringApplication.run(MySpringBootApplication.class, args);
      }
  }
  </code></pre>
  
  <p><em>application.properties:</em></p>
  
  <pre><code>server.port=5566
  spring.application.name=@project.name@
  # data source
  spring.jpa.hibernate.ddl-auto=update
  spring.datasource.url=jdbc:mysql://localhost:3306/springboot
  spring.datasource.username=root
  spring.datasource.password=
  # Session
  spring.session.store-type=none
  # Security
  security.basic.enabled=false
  
  # logging
  logging.pattern.console=%d{yyyy-MM-dd HH:mm:ss} %-5level %logger{36} - %msg%n
  logging.level.org.hibernate.SQL=debug
  #logging.level.org.hibernate.type.descriptor.sql=trace
  logging.level.=error
  </code></pre>