Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/spring-mvc/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何使用有效负载变量在Springboots中构造@service_Spring_Spring Mvc_Spring Boot - Fatal编程技术网

如何使用有效负载变量在Springboots中构造@service

如何使用有效负载变量在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")

我刚穿春装,所以我希望这不是一个愚蠢的问题

我有一个@Service需要启动一个class属性,这个属性需要一个来自控制器中RestPayload的信息。我没有找到最值得推荐的方法

     @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);

    }