title: Error creating bean with name *
body: <p>i am doing that tutorial at the moment:</p>
  
  <p><a href="https://github.com/ubilife/tutorials/tree/master/spring/tutorial4" rel="nofollow noreferrer">https://github.com/ubilife/tutorials/tree/master/spring/tutorial4</a></p>
  
  <p>When I clone the repository everything works exactly like it is writte there.</p>
  
  <p>The tutorial had among others this class:</p>
  
  <p><strong>Config.java</strong></p>
  
  <pre><code>@Configuration
  @ComponentScan
  public class Config {
  
      @Bean
      public DataSource datasource() {
          return new EmbeddedDatabaseBuilder().setType(EmbeddedDatabaseType.H2).addScript("schema.sql").build();
      }
  
      @Bean
      public JdbcOperations jdbcTemplate(DataSource ds) {
          return new JdbcTemplate(ds);        
      }
  
  }
  </code></pre>
  
  <p>Now I tried to make use of what I've learned. I use SpringBoot with Intellij Ultimate 20017 and I wrote among others that class</p>
  
  <pre><code>@Configuration
  @ComponentScan
  public class SpringRootConfig {
  
      @Bean(name = "scriptedDataSource")
      public DataSource datasource() {
          return new EmbeddedDatabaseBuilder().setType(EmbeddedDatabaseType.H2).addScript("schema.sql").build();
      }
  
      @Bean
      public JdbcOperations jdbcTemplate(@Qualifier("scriptedDataSource") DataSource dataSource) {
          System.out.println("jdbcTemplate()");
          return new JdbcTemplate(dataSource);
      }
  }
  </code></pre>
  
  <p>First I had the Problem of duplicate Beans which Intellij could not handle. I solved that by use Qualifiers as you can see. </p>
  
  <p>But now I got a new Error which I cannot solve with google.</p>
  
  <pre><code>Error starting ApplicationContext. To display the auto-configuration report re-run your application with 'debug' enabled.
  2017-05-28 14:38:50.428 ERROR 2020 --- [           main] o.s.boot.SpringApplication               : Application startup failed
  
  org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'scriptedDataSource' defined in class path resource [com/example/demo/SpringRootConfig.class]: Bean instantiation via factory method failed; nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate [javax.sql.DataSource]: Factory method 'datasource' threw exception; nested exception is org.springframework.jdbc.datasource.init.CannotReadScriptException: Cannot read SQL script from class path resource [schema.sql]; nested exception is java.io.FileNotFoundException: class path resource [schema.sql] cannot be opened because it does not exist
      at org.springframework.beans.factory.support.ConstructorResolver.instantiateUsingFactoryMethod(ConstructorResolver.java:599) ~[spring-beans-4.3.8.RELEASE.jar:4.3.8.RELEASE]
      at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.instantiateUsingFactoryMethod(AbstractAutowireCapableBeanFactory.java:1173) ~[spring-beans-4.3.8.RELEASE.jar:4.3.8.RELEASE]
      at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBeanInstance(AbstractAutowireCapableBeanFactory.java:1067) ~[spring-beans-4.3.8.RELEASE.jar:4.3.8.RELEASE]
      at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:513) ~[spring-beans-4.3.8.RELEASE.jar:4.3.8.RELEASE]
      at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:483) ~[spring-beans-4.3.8.RELEASE.jar:4.3.8.RELEASE]
      at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:306) ~[spring-beans-4.3.8.RELEASE.jar:4.3.8.RELEASE]
      at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:230) ~[spring-beans-4.3.8.RELEASE.jar:4.3.8.RELEASE]
      at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:302) ~[spring-beans-4.3.8.RELEASE.jar:4.3.8.RELEASE]
      at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:197) ~[spring-beans-4.3.8.RELEASE.jar:4.3.8.RELEASE]
      at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:761) ~[spring-beans-4.3.8.RELEASE.jar:4.3.8.RELEASE]
      at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:866) ~[spring-context-4.3.8.RELEASE.jar:4.3.8.RELEASE]
      at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:542) ~[spring-context-4.3.8.RELEASE.jar:4.3.8.RELEASE]
      at org.springframework.boot.context.embedded.EmbeddedWebApplicationContext.refresh(EmbeddedWebApplicationContext.java:122) ~[spring-boot-1.5.3.RELEASE.jar:1.5.3.RELEASE]
      at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:737) [spring-boot-1.5.3.RELEASE.jar:1.5.3.RELEASE]
      at org.springframework.boot.SpringApplication.refreshContext(SpringApplication.java:370) [spring-boot-1.5.3.RELEASE.jar:1.5.3.RELEASE]
      at org.springframework.boot.SpringApplication.run(SpringApplication.java:314) [spring-boot-1.5.3.RELEASE.jar:1.5.3.RELEASE]
      at org.springframework.boot.SpringApplication.run(SpringApplication.java:1162) [spring-boot-1.5.3.RELEASE.jar:1.5.3.RELEASE]
      at org.springframework.boot.SpringApplication.run(SpringApplication.java:1151) [spring-boot-1.5.3.RELEASE.jar:1.5.3.RELEASE]
      at com.example.demo.DemoApplication.main(DemoApplication.java:17) [classes/:na]
  Caused by: org.springframework.beans.BeanInstantiationException: Failed to instantiate [javax.sql.DataSource]: Factory method 'datasource' threw exception; nested exception is org.springframework.jdbc.datasource.init.CannotReadScriptException: Cannot read SQL script from class path resource [schema.sql]; nested exception is java.io.FileNotFoundException: class path resource [schema.sql] cannot be opened because it does not exist
      at org.springframework.beans.factory.support.SimpleInstantiationStrategy.instantiate(SimpleInstantiationStrategy.java:189) ~[spring-beans-4.3.8.RELEASE.jar:4.3.8.RELEASE]
      at org.springframework.beans.factory.support.ConstructorResolver.instantiateUsingFactoryMethod(ConstructorResolver.java:588) ~[spring-beans-4.3.8.RELEASE.jar:4.3.8.RELEASE]
      ... 18 common frames omitted
  Caused by: org.springframework.jdbc.datasource.init.CannotReadScriptException: Cannot read SQL script from class path resource [schema.sql]; nested exception is java.io.FileNotFoundException: class path resource [schema.sql] cannot be opened because it does not exist
      at org.springframework.jdbc.datasource.init.ScriptUtils.executeSqlScript(ScriptUtils.java:450) ~[spring-jdbc-4.3.8.RELEASE.jar:4.3.8.RELEASE]
      at org.springframework.jdbc.datasource.init.ResourceDatabasePopulator.populate(ResourceDatabasePopulator.java:238) ~[spring-jdbc-4.3.8.RELEASE.jar:4.3.8.RELEASE]
      at org.springframework.jdbc.datasource.init.DatabasePopulatorUtils.execute(DatabasePopulatorUtils.java:48) ~[spring-jdbc-4.3.8.RELEASE.jar:4.3.8.RELEASE]
      at org.springframework.jdbc.datasource.embedded.EmbeddedDatabaseFactory.initDatabase(EmbeddedDatabaseFactory.java:196) ~[spring-jdbc-4.3.8.RELEASE.jar:4.3.8.RELEASE]
      at org.springframework.jdbc.datasource.embedded.EmbeddedDatabaseFactory.getDatabase(EmbeddedDatabaseFactory.java:153) ~[spring-jdbc-4.3.8.RELEASE.jar:4.3.8.RELEASE]
      at org.springframework.jdbc.datasource.embedded.EmbeddedDatabaseBuilder.build(EmbeddedDatabaseBuilder.java:270) ~[spring-jdbc-4.3.8.RELEASE.jar:4.3.8.RELEASE]
      at com.example.demo.SpringRootConfig.datasource(SpringRootConfig.java:21) ~[classes/:na]
      at com.example.demo.SpringRootConfig$$EnhancerBySpringCGLIB$$6e8fdc42.CGLIB$datasource$1(&lt;generated&gt;) ~[classes/:na]
      at com.example.demo.SpringRootConfig$$EnhancerBySpringCGLIB$$6e8fdc42$$FastClassBySpringCGLIB$$39d24068.invoke(&lt;generated&gt;) ~[classes/:na]
      at org.springframework.cglib.proxy.MethodProxy.invokeSuper(MethodProxy.java:228) ~[spring-core-4.3.8.RELEASE.jar:4.3.8.RELEASE]
      at org.springframework.context.annotation.ConfigurationClassEnhancer$BeanMethodInterceptor.intercept(ConfigurationClassEnhancer.java:358) ~[spring-context-4.3.8.RELEASE.jar:4.3.8.RELEASE]
      at com.example.demo.SpringRootConfig$$EnhancerBySpringCGLIB$$6e8fdc42.datasource(&lt;generated&gt;) ~[classes/:na]
      at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[na:1.8.0_131]
      at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) ~[na:1.8.0_131]
      at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[na:1.8.0_131]
      at java.lang.reflect.Method.invoke(Method.java:498) ~[na:1.8.0_131]
      at org.springframework.beans.factory.support.SimpleInstantiationStrategy.instantiate(SimpleInstantiationStrategy.java:162) ~[spring-beans-4.3.8.RELEASE.jar:4.3.8.RELEASE]
      ... 19 common frames omitted
  Caused by: java.io.FileNotFoundException: class path resource [schema.sql] cannot be opened because it does not exist
      at org.springframework.core.io.ClassPathResource.getInputStream(ClassPathResource.java:172) ~[spring-core-4.3.8.RELEASE.jar:4.3.8.RELEASE]
      at org.springframework.core.io.support.EncodedResource.getReader(EncodedResource.java:141) ~[spring-core-4.3.8.RELEASE.jar:4.3.8.RELEASE]
      at org.springframework.jdbc.datasource.init.ScriptUtils.readScript(ScriptUtils.java:279) ~[spring-jdbc-4.3.8.RELEASE.jar:4.3.8.RELEASE]
      at org.springframework.jdbc.datasource.init.ScriptUtils.executeSqlScript(ScriptUtils.java:447) ~[spring-jdbc-4.3.8.RELEASE.jar:4.3.8.RELEASE]
      ... 35 common frames omitted
  
  
  Process finished with exit code 1
  </code></pre>
  
  <p>So first of all I dont understand why cloning the tutors code is working fine and as soon as I try it fails (I even copied for test reasons his config.java but still get errors!)</p>
  
  <p>And of course it would be super nice if you can help me to solve this problem.</p>
  
  <p>Thank you a lot!
  If you need any more files please just ask.
  My Repo is here <a href="https://github.com/realsony/h2TestEnv/tree/master/src" rel="nofollow noreferrer">https://github.com/realsony/h2TestEnv/tree/master/src</a></p>