Обновить
0

Пользователь

Отправить сообщение
Пробую Спринг, у меня вопрос к разбирающимся: ловлю BeanCreationException, гуглопоиск не помогЮ помогут местные?
WARNING: Exception encountered during context initialization — cancelling refresh attempt: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'org.springframework.context.annotation.internalAsyncAnnotationProcessor' defined in class path resource [org/springframework/scheduling/annotation/ProxyAsyncConfiguration.class]: Bean instantiation via factory method failed; nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate [org.springframework.scheduling.annotation.AsyncAnnotationBeanPostProcessor]: Factory method 'asyncAdvisor' threw exception; nested exception is java.lang.IllegalArgumentException: @EnableAsync annotation metadata was not injected

Единственный указатель ошибки на строку создания контекста:
public class App {
    public static void main(String[] args) {
        ApplicationContext ctx = new AnnotationConfigApplicationContext(MyConfig.class);
        DataSource dataSource = ctx.getBean(DataSource.class);
        UserDAO userDAO = ctx.getBean(UserDAO.class);
    }
}

Класс конфига:
@Configuration
@ComponentScan
public class MyConfig { 
  @Bean
@Scope("singleton")
  public  DataSource dataSource(){
    JdbcDataSource datasource = new JdbcDataSource();
    datasource.setURL("jdbc:h2:~/test");
    datasource.setUser("sa");
    datasource.setPassword("");
    return datasource;
  }
}

класс ДАОшки:
@Component
public class UserDAO {
    private DataSource dataSource;

    public UserDAO(@Autowired DataSource dataSource){
        this.dataSource = dataSource;
    }

    public User findById(int id) {
        try (Connection connection = dataSource.getConnection()) { // (1)
            PreparedStatement selectStatement = connection.prepareStatement("select * from users where id =  ?");

        } catch (SQLException e) {
            e.printStackTrace();
        }
        return new User();
    }
}

В ПОМ файле — зависимость spring-context и H2.

Информация

В рейтинге
Не участвует
Зарегистрирован
Активность