@Service
public class UserService implements UserServiceInterface{
@Autowired
UserRepository repo;
@Autowired
BCryptPasswordEncoder crypt;
@Autowired
RoleRepository roleRepo;
public void save(User user) {
user.setPassword(crypt.encode(user.getPassword()));
Role role = roleRepo.findByRole("USER");
user.setRoles(new HashSet<Role>(Arrays.asList(role)));
repo.save(user);
}
@Override
public User findByUsername(String userName) {
User user = repo.findByUserName(userName);
return user;
}
}
@Service
public interface UserServiceInterface {
public void save(User user);
public User findByUsername(String userName);
}
@Configuration
@EnableWebSecurity
public class SecurityConfiguration extends
WebSecurityConfigurerAdapter {
@Autowired
UserPrincipleDetailsService user;
@Autowired
private SimpleAuthenticationSuccessHandler successHandler;
@Override
protected void configure(AuthenticationManagerBuilder auth) throws
Exception {
auth.authenticationProvider(daoAuthenticationProvider());
}
@Override
protected void configure(HttpSecurity http) throws Exception {
http.authorizeRequests()
.antMatchers("/assets/css/**").permitAll()
.antMatchers("/img/**").permitAll()
.antMatchers("/home").permitAll()
.antMatchers("/register/**").permitAll()
.antMatchers("/registerUser").permitAll()
.antMatchers("/admin/**").hasRole("ADMIN")
.antMatchers("/user/**").hasAnyRole("ADMIN","USER")
.anyRequest().authenticated()
.and()
.csrf().disable()
.formLogin()
.successHandler(successHandler)
.loginPage("/home").permitAll()
.loginProcessingUrl("/signin")
.failureUrl("/home?error=true")
.and()
.logout().logoutRequestMatcher(new
AntPathRequestMatcher("/logout"))
.logoutSuccessUrl("/home")
.and()
.exceptionHandling().accessDeniedPage("/home");
}
@Bean
DaoAuthenticationProvider daoAuthenticationProvider() {
DaoAuthenticationProvider dao = new
DaoAuthenticationProvider();
dao.setPasswordEncoder(passwordEncoder());
dao.setUserDetailsService(user);
return dao;
}
@Bean
PasswordEncoder passwordEncoder() {
return new BCryptPasswordEncoder();
}
}
改变
@Autowired
BCryptPasswordEncoder crypt;
至
@Autowired
PasswordEncoder crypt
或更改passwordEncoder方法
@Bean
BCryptPasswordEncoder passwordEncoder() {
return new BCryptPasswordEncoder();
}
我正在使用Spring Boot 2.2.4并尝试自定义执行器 以下是相关的课程
我想在xml JDBCTemolate上进行配置。 看起来是这样的 JDBCrepository: 控制器:
控制器: 型号: 存储库: web.xml
我尝试构建简单的Maven springMVC应用程序。当我试图将应用程序部署到我的服务器时,下面抛出了异常。 unsatisfiedDependencyException:创建com.phapp.comfiguration.webconfiguration中定义的名为“View Resolver”的bean时出错:通过方法“View Resolver”参数0表示未满足的依赖关系;嵌套异常是org
当试图用包含所有上下文配置的抽象类运行stepdefs时,spring看到2个不同的beans parent和step def 我使用的是Spring Booking版本:2.6.4,JUnit 5和Cucumber版本7.2.3 异常堆栈跟踪: io.cucumber.core.runtime.CucumberExecutionContext.runTestCase:没有可用的“Cucumber
我尝试自动连接我的mapstruct mapper: 这是可行的: 但是为什么我不能使用: 我得到以下错误: 导致原因:org . spring framework . beans . factory . nosuchbeandidefinitionexception:没有类型为“pl . comp . window . application . mapper . windowdtomapper