如何使用有效负载变量在Springboots中构造@service
我刚穿春装,所以我希望这不是一个愚蠢的问题 我有一个@Service需要启动一个class属性,这个属性需要一个来自控制器中RestPayload的信息。我没有找到最值得推荐的方法如何使用有效负载变量在Springboots中构造@service,spring,spring-mvc,spring-boot,Spring,Spring Mvc,Spring Boot,我刚穿春装,所以我希望这不是一个愚蠢的问题 我有一个@Service需要启动一个class属性,这个属性需要一个来自控制器中RestPayload的信息。我没有找到最值得推荐的方法 @RestController public class UserController { @Autowired private UserService userService; @RequestMapping("/searchUser")
@RestController
public class UserController {
@Autowired
private UserService userService;
@RequestMapping("/searchUser")
public List<UserWrapper> searchUser(@RequestBody UserWrapper userWrapper) {
List<UserWrapper> returnUserWrapper = userService.findByName(userWrapper);
return returnUserWrapper;
}
}
字符串dn和字符串密码将出现在REST负载中,但其他属性来自属性文件
希望有人能为我提供ldap身份验证的最佳实践指南。您应该了解spring安全性:
dn
和密码后,使用两个设置器
,然后调用一个方法,该方法将在您的服务内调用ldap。
@Service
public class UserService {
private LdapTemplate ldapTemplate;
public static final String BASE_DN = "xxxxxxx";
@Value( value = "${sample.ldap.url}" )
private String ldapUrl;
@Value( value = "${sample.ldap.base}" )
private String ldapBase;
public UserService() {
}
public UserService(String dn, String password) {
LdapContextSource ctxSrc = new LdapContextSource();
System.out.println(this.ldapUrl);
ctxSrc.setUrl(ldapUrl);
ctxSrc.setBase(ldapBase);
ctxSrc.setUserDn(dn);
ctxSrc.setPassword(password);
ctxSrc.afterPropertiesSet(); // this method should be called.\
this.ldapTemplate = new LdapTemplate(ctxSrc);
}