无法将自动装配的DataSource导入WebSecurityConfigurerAdapter

时间:2015-11-10 10:38:01

标签: java spring spring-security spring-boot

尝试将jdbc auth添加到spring-boot app

Application.java

@Override
protected void onResume() {
    super.onResume();
    this.architectView.onResume();
}

@Override
protected void onPause() {
    super.onPause();
    this.architectView.onPause();
}

@Override
protected void onDestroy() {
    super.onDestroy();
    this.architectView.onDestroy();
}


//my own function
private void makeUseOfNewLocation(Location location) {
    try {
        //MAKE SURE YOU CALL THIS
        architectView.setLocation(location.getLatitude(), location.getLongitude(), location.getAltitude(), location.getAccuracy());
        this.architectView.load("poi_1/index.html");
    } catch (IOException e) {
        e.printStackTrace();
    }
}

WebSecurityConfig.java

@SpringBootApplication
public class Application {

    @Value("${spring.datasource.driverClassName}")
    private String databaseDriverClassName;

    @Value("${spring.datasource.url}")
    private String datasourceUrl;

    @Value("${spring.datasource.username}")
    private String databaseUsername;

    @Value("${spring.datasource.password}")
    private String databasePassword;

    @Bean
    public DataSource dataSource() {

        DataSource dataSource = new DataSource();

        dataSource.setDriverClassName(databaseDriverClassName);
        dataSource.setUrl(datasourceUrl);
        dataSource.setUsername(databaseUsername);
        dataSource.setPassword(databasePassword);

        return dataSource;
    }

    public static void main(String[] args) {
        SpringApplication.run(Application.class, args);
    }
}

所有示例都说明这已经足够了,但@Autowire不起作用

IDEA告诉“无法自动装配。没有发现DataSource类型的bean”

项目结构

com.acsent
    config
        WebSecurityConfig.java

    Application.java

2 个答案:

答案 0 :(得分:0)

添加

@ComponentScan("com.acsent")

public class WebSecurityConfig

解决问题

答案 1 :(得分:0)

我以完全不同的方式解决了这个问题。 通过hibernate使用db访问。 您可以在github

查看来源