2017-12-04 13 views
0

ウェブアプリケーションでspring-data-ldapの設定に問題があります。 私が行ったことを要約します: spring-data-ldap依存関係を持つmaven(ldap-modelと呼ばれる)プロジェクトを作成し、User.java(Entry)クラスと対応するRepository:UserRepositoryを作成しました。 それから、以前に作成された解放依存関係(ldap-model)を持つ新しいspring mvc Webプロジェクトを作成しました。 私はそう、XML設定を使用したい:スプリングデータのLDAP設定

ここ

ルートのcontext.xml

<?xml version="1.0" encoding="UTF-8"?> 
<beans xmlns="http://www.springframework.org/schema/beans" 
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:context="http://www.springframework.org/schema/context" 
xmlns:ldap="http://www.springframework.org/schema/ldap" 
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd http://www.springframework.org/schema/ldap http://www.springframework.org/schema/ldap/spring-ldap.xsd"> 

<!-- Root Context: defines shared resources visible to all other web components --> 


<context:property-placeholder location="classpath:ldap.properties" /> 
<context:annotation-config /> 

<ldap:context-source id="contextSource" 
    password="${ldap.contextSource.password}" url="${ldap.contextSource.url}" 
    username="${ldap.contextSource.userDn}" base="${ldap.contextSource.base}"></ldap:context-source> 

<ldap:repositories base-package="eu.test.ldap.repository"> 
</ldap:repositories> 

<ldap:ldap-template id="ldapTemplate" 
    context-source-ref="contextSource"></ldap:ldap-template> 

<bean class="eu.test.webapp.UserService"> 
</bean> 

を私はタグLDAPとの最初の問題があります:Ctrlキー+スペースとリポジトリ、それが示唆されていますがコードの残りの部分に続いて

Multiple annotations found at this line: 
- Configuration problem: Cannot locate BeanDefinitionParser for element [repositories] Offending resource: file [C:/Progetti/ 
Workspace di test/ldap-webapp/src/main/webapp/WEB-INF/spring/root-context.xml] 
- Cannot locate BeanDefinitionParser for element [repositories] 

:私は、それは、このエラーを与えてコンパイルされません

UserService.java

public class UserService implements BaseLdapNameAware { 
private final UserRepository userRepo; 
private LdapName baseLdapPath; 

@Autowired 
public UserService(UserRepository userRepo) { 
    this.userRepo = userRepo; 
} 

public void find() 
{ 
    User u = userRepo.findByUid("test.test"); 
    System.out.println(u.getUid()); 
} 

@Override 
public void setBaseLdapPath(LdapName baseLdapPath) { 
    this.baseLdapPath = baseLdapPath; 

}} 

ldap.properties

ldap.contextSource.url=********* 
ldap.contextSource.userDn=cn=********* 
ldap.contextSource.password=********* 
ldap.contextSource.base=********* 

サーブレットのcontext.xml

<?xml version="1.0" encoding="UTF-8"?> 
<beans:beans xmlns="http://www.springframework.org/schema/mvc" 
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
xmlns:beans="http://www.springframework.org/schema/beans" 
xmlns:context="http://www.springframework.org/schema/context" 
xsi:schemaLocation="http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc.xsd 
    http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd 
    http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd"> 

<!-- DispatcherServlet Context: defines this servlet's request-processing infrastructure --> 

<!-- Enables the Spring MVC @Controller programming model --> 
<annotation-driven /> 

<!-- Handles HTTP GET requests for /resources/** by efficiently serving up static resources in the ${webappRoot}/resources directory --> 
<resources mapping="/resources/**" location="/resources/" /> 

<!-- Resolves views selected for rendering by @Controllers to .jsp resources in the /WEB-INF/views directory --> 
<beans:bean class="org.springframework.web.servlet.view.InternalResourceViewResolver"> 
    <beans:property name="prefix" value="/WEB-INF/views/" /> 
    <beans:property name="suffix" value=".jsp" /> 
</beans:bean> 

<context:component-scan base-package="eu.test.webapp" /> 

HomeController.java

@Controller 
public class HomeController { 

private static final Logger logger = LoggerFactory.getLogger(HomeController.class); 

@Autowired 
private UserService userService; 


@RequestMapping(value = "/", method = RequestMethod.GET) 
public String home(Locale locale, Model model) { 
    logger.info("Welcome home! The client locale is {}.", locale); 

    userService.find(); 


    return "home"; 
} 

エラー以外に何か間違いがありますか?

また、xmlではなくJavaの設定を作成しようとしました 以前に作成された解放依存関係(ldap-model)で新しいspring mvc Webプロジェクトを作成しました。

@Configuration 
@PropertySource("classpath:ldap.properties") 
@ComponentScan(basePackages = {"eu.test.*"}) 
@Profile("default") 
@EnableLdapRepositories(basePackages = "eu.test.ldap.repository.**") 
    public class AppConfig { 

@Autowired 
private Environment env; 

@Bean 
public LdapContextSource contextSource() { 
    LdapContextSource contextSource = new LdapContextSource(); 
    contextSource.setUrl(env.getRequiredProperty("ldap.contextSource.url")); 
    contextSource.setBase(env.getRequiredProperty("ldap.contextSource.base")); 
    contextSource.setUserDn(env.getRequiredProperty("ldap.contextSource.userDn")); 
    contextSource.setPassword(env.getRequiredProperty("ldap.contextSource.password")); 
    return contextSource; 
} 

@Bean 
public LdapTemplate ldapTemplate() { 
    return new LdapTemplate(contextSource()); 
} 

}

UserService.java

@Service 

パブリッククラスUserServiceの{

@Autowired 
private UserRepository userRepository; 

public String getUsernameByUid(String uid) 
{ 
    return userRepository.findByUid(uid).getUsername(); 
} 

}上記のようなldap.properties

私は何かが欠けていると確信しているHomeController.java

@Controller 
public class HomeController { 

private static final Logger logger = LoggerFactory.getLogger(HomeController.class); 

@Autowired 
private UserService userService; 

@RequestMapping(value = "/", method = RequestMethod.GET) 
public String home(Locale locale, Model model) { 

    String username = userService.getUsernameByUid("nome.cognome"); 

    return "home"; 
} 

}

は、UserServiceのは

nullで誰もがこれらの機能を持つ例のWebプロジェクトを持っていますか?

ご迷惑をおかけして申し訳ありません。ありがとうございました。

答えて

0

まず、HomeControllerのuserServiceAttributeのgetterメソッドとsetterメソッドが定義されていないため、userServiceはnullです。

BeanDefinitionParserがないと、spring-ldap-core 2.3以降にxml構成を解析する際に違いがあるようです。 LdapNamespaceHandlerクラスを見ると、タグ "リポジトリ"に対してハンドラが定義されていないことがわかります。 spring-ldap.xsdに相当する変更がないので、奇妙に聞こえます。 とにかく、xml構成のアプローチを使いたいのであれば、spring-ldap-core 2.3の代わりにspring-ldap-core 2.2を使い、単純にpom.xmlを変更すれば解決できます。

チャオ

関連する問題