Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Error:
- Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'org.springframework.security.config.annotation.web.configuration.WebSecurityConfiguration': Injection of autowired dependencies failed; nested exception is org.springframework.beans.factory.BeanCreationException: Could not autowire method: public void org.springframework.security.config.annotation.web.configuration.WebSecurityConfiguration.setFilterChainProxySecurityConfigurer(org.springframework.security.config.annotation.ObjectPostProcessor,java.util.List) throws java.lang.Exception; nested exception is org.springframework.beans.factory.BeanExpressionException: Expression parsing failed; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'webSecurityConfiguration': Injection of autowired dependencies failed; nested exception is org.springframework.beans.factory.BeanCreationException: Could not autowire field: private showcase.CustomUserDetailsService showcase.WebSecurityConfiguration.customUserDetailsService; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'userDetailsService': Injection of autowired dependencies failed; nested exception is org.springframework.beans.factory.BeanCreationException: Could not autowire field: showcase.AppUserRepository showcase.CustomUserDetailsService.repository; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'appUserRepository': Cannot create inner bean '(inner bean)#6bd8d7e8' of type [org.springframework.orm.jpa.SharedEntityManagerCreator] while setting bean property 'entityManager'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name '(inner bean)#6bd8d7e8': Cannot resolve reference to bean 'entityManagerFactory' while setting constructor argument; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'entityManagerFactory' defined in class path resource [org/springframework/boot/autoconfigure/orm/jpa/HibernateJpaAutoConfiguration.class]: Instantiation of bean failed; nested exception is org.springframework.beans.factory.BeanDefinitionStoreException: Factory method [public org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean org.springframework.boot.autoconfigure.orm.jpa.JpaBaseConfiguration.entityManagerFactory(org.springframework.orm.jpa.JpaVendorAdapter)] threw exception; nested exception is org.springframework.beans.factory.NoSuchBeanDefinitionException: No qualifying bean of type [javax.sql.DataSource] is defined
- Application.java
- @EnableAutoConfiguration
- @EnableJpaRepositories(basePackageClasses = AppUserRepository.class)
- @Configuration
- @ComponentScan
- public class Application {
- public static void main(String[] args) {
- SpringApplication.run(Application.class, args);
- }
- @Bean
- MultipartConfigElement multipartConfigElement() {
- MultiPartConfigFactory factory = new MultiPartConfigFactory();
- factory.setMaxFileSize("128KB");
- factory.setMaxRequestSize("128KB");
- return factory.createMultipartConfig();
- }
- }
- AppUserRepository.java
- @Repository
- public interface AppUserRepository extends CrudRepository<AppUser, Long>{
- public AppUser findByUserName(String username);
- public void delete(AppUser user);
- }
- WebSecurityConfiguration.java
- @Configuration
- @EnableWebSecurity
- public class WebSecurityConfiguration extends WebSecurityConfigurerAdapter {
- @Autowired
- private CustomUserDetailsService customUserDetailsService;
- @Override
- @Autowired
- protected void configure(AuthenticationManagerBuilder auth) throws Exception {
- // @formatter:off
- auth.userDetailsService(customUserDetailsService);
- // @formatter:on
- }
- CustomUserDetailsService.java
- @Service("userDetailsService")
- public class CustomUserDetailsService implements UserDetailsService {
- @Autowired
- AppUserRepository repository;
- @Autowired
- private UserService userService;
- private static final Logger logger = LoggerFactory.getLogger(CustomUserDetailsService.class);
- static final PasswordEncoder passwordEncoder = new BCryptPasswordEncoder();
- @Override
- public UserDetails loadUserByUsername(String name) throws UsernameNotFoundException {
- logger.info("username:"+name);
- AppUser u = repository.findByUserName(name);
- if (u == null)
- throw new UsernameNotFoundException("User details not found with this username: " + name);
- String username = u.getUsername();
- String password = u.getPassword();
- List authList = new ArrayList();
- authList.add(new SimpleGrantedAuthority("USER"));
- User user = new User(username, password, authList);
- return user;
- }
- UserService.java
- @Service("userService")
- public class UserService {
- @Autowired
- AppUserRepository repository;
- public AppUser registerNewAppUser(AppUser user) {
- AppUser u = repository.findByUserName(user.getUsername());
- if (u!=null)
- return null;
- return repository.save(user);
- }
Advertisement
Add Comment
Please, Sign In to add comment