Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- @Configuration
- @EnableWebMvc
- @EnableTransactionManagement
- @ComponentScan(basePackages = "com.project.shopping")
- public class ShoppingServletConfig {
- @Primary
- @Bean(name = "dataSource")
- public DataSource dataSource() {
- BasicDataSource dataSource = new BasicDataSource();
- dataSource.setDriverClassName("com.mysql.jdbc.Driver");
- dataSource.setUrl("jdbc:mysql://localhost:3306/shopping");
- dataSource.setUsername("root");
- dataSource.setPassword("root");
- return dataSource;
- }
- }
- @Configuration
- @EnableWebSecurity
- public class SpringSecurityConfig extends WebSecurityConfigurerAdapter {
- @Autowired
- @Qualifier("dataSource")
- DataSource dataSource;
- @Autowired
- public void configureGlobal(AuthenticationManagerBuilder auth) throws Exception {
- auth
- .jdbcAuthentication()
- .dataSource(dataSource)
- .usersByUsernameQuery(
- "select username,password, enabled from user where user_name=?")
- .authoritiesByUsernameQuery(
- "select username, role from user_roles where user_name=?");
- }
- org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'springSecurityConfig':
- Unsatisfied dependency expressed through field 'dataSource'; nested exception is org.springframework.beans.factory.NoSuchBeanDefinitionException: No qualifying bean of type 'javax.sql.DataSource' available: expected at least 1 bean which qualifies as autowire candidate. Dependency annotations: {@org.springframework.beans.factory.annotation.Autowired(required=true), @org.springframework.beans.factory.annotation.Qualifier(value=dataSource)}
- Caused by: org.springframework.beans.factory.NoSuchBeanDefinitionException: No qualifying bean of type 'javax.sql.DataSource' available: expected at least 1 bean which qualifies as autowire candidate.
- Dependency annotations: {@org.springframework.beans.factory.annotation.Autowired(required=true), @org.springframework.beans.factory.annotation.Qualifier(value=dataSource)}
Add Comment
Please, Sign In to add comment