Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Convert XML configurations to Java-based configurations (all easy cases) #589

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
/*
* Copyright 2005-2013 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.springframework.ldap.configuration;

import javax.naming.directory.SearchControls;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;


/**
* Generated Java based configuration
*
*/
@Configuration
public class LdapNamespaceConfigPoolingTestSpecified {


@Bean("searchControls")
public SearchControls searchControls() {
return new SearchControls();
}

}
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
<?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:ldap="http://www.springframework.org/schema/ldap"
xsi:schemaLocation="http://www.springframework.org/schema/beans https://www.springframework.org/schema/beans/spring-beans.xsd http://www.springframework.org/schema/ldap https://www.springframework.org/schema/ldap/spring-ldap.xsd">
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:ldap="http://www.springframework.org/schema/ldap"
xsi:schemaLocation="http://www.springframework.org/schema/beans
https://www.springframework.org/schema/beans/spring-beans.xsd
http://www.springframework.org/schema/ldap
https://www.springframework.org/schema/ldap/spring-ldap.xsd">

<ldap:context-source password="apassword" url="ldap://localhost:389" username="uid=admin">
<ldap:pooling2
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,24 +2,28 @@
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:ldap="http://www.springframework.org/schema/ldap"
xsi:schemaLocation="http://www.springframework.org/schema/beans https://www.springframework.org/schema/beans/spring-beans.xsd http://www.springframework.org/schema/ldap https://www.springframework.org/schema/ldap/spring-ldap.xsd">


<ldap:context-source password="apassword" url="ldap://localhost:389" username="uid=admin">
<ldap:pooling
test-on-borrow="true"
test-on-return="true"
test-while-idle="true"
min-evictable-time-millis="123"
eviction-run-interval-millis="321"
tests-per-eviction-run="22"
validation-query-base="ou=test"
validation-query-filter="objectclass=person"
validation-query-search-controls-ref="searchControls"
non-transient-exceptions="javax.naming.CannotProceedException,javax.naming.CommunicationException" />
</ldap:context-source>

<bean class="javax.naming.directory.SearchControls" id="searchControls" />

<ldap:ldap-template />
</beans>
xsi:schemaLocation="http://www.springframework.org/schema/beans
https://www.springframework.org/schema/beans/spring-beans.xsd
http://www.springframework.org/schema/ldap
https://www.springframework.org/schema/ldap/spring-ldap.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context.xsd"
xmlns:context="http://www.springframework.org/schema/context">
<ldap:context-source password="apassword"
url="ldap://localhost:389"
username="uid=admin">
<ldap:pooling test-on-borrow="true"
test-on-return="true"
test-while-idle="true"
min-evictable-time-millis="123"
eviction-run-interval-millis="321"
tests-per-eviction-run="22"
validation-query-base="ou=test"
validation-query-filter="objectclass=person"
validation-query-search-controls-ref="searchControls"
non-transient-exceptions="javax.naming.CannotProceedException,javax.naming.CommunicationException"/>
</ldap:context-source>
<context:annotation-config/>
<bean class="org.springframework.ldap.configuration.LdapNamespaceConfigPoolingTestSpecified"/>
<ldap:ldap-template/>
</beans>
2 changes: 2 additions & 0 deletions ldif/ldif-batch/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,11 @@ dependencies {
exclude group: "org.springframework", module: "spring-aop"
}


testCompile "junit:junit:$junitVersion",
"org.springframework:spring-context:$springVersion",
"org.springframework:spring-aop:$springVersion",
"org.springframework:spring-orm:${springVersion}",
"org.springframework:spring-test:$springVersion",
"org.assertj:assertj-core:$assertjVersion"

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,99 @@
/*
* Copyright 2005-2013 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.springframework.ldap.configuration;

import org.springframework.batch.core.launch.support.SimpleJobLauncher;
import org.springframework.batch.core.repository.JobRepository;
import org.springframework.batch.core.repository.support.MapJobRepositoryFactoryBean;
import org.springframework.batch.item.file.FlatFileItemWriter;
import org.springframework.batch.support.transaction.ResourcelessTransactionManager;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.core.io.FileSystemResource;
import org.springframework.core.task.SyncTaskExecutor;
import org.springframework.ldap.ldif.batch.LdifAggregator;
import org.springframework.ldap.ldif.batch.MappingLdifReader;
import org.springframework.ldap.ldif.batch.MyMapper;


/**
* Generated Java based configuration
*/
@Configuration
public class Batch20ApplicationContextTest2 {


@Bean("itemReader1")
public MappingLdifReader itemReader1(@Qualifier("recordMapper")
MyMapper recordMapper) {
MappingLdifReader bean = new MappingLdifReader();
bean.setResource(new FileSystemResource("src/test/resources/test.ldif"));
bean.setRecordsToSkip(1);
bean.setRecordMapper(recordMapper);
return bean;
}

@Bean("taskExecutor")
public SyncTaskExecutor taskExecutor() {
return new SyncTaskExecutor();
}

@Bean("jobLauncher")
public SimpleJobLauncher jobLauncher(
@Qualifier("jobRepository")
MapJobRepositoryFactoryBean jobRepository,
@Qualifier("taskExecutor")
SyncTaskExecutor taskExecutor) throws Exception {
SimpleJobLauncher bean = new SimpleJobLauncher();
bean.setJobRepository((JobRepository) jobRepository.getObject());
bean.setTaskExecutor(taskExecutor);
return bean;
}

@Bean("itemReader2")
public MappingLdifReader itemReader2(
@Qualifier("recordMapper")
MyMapper recordMapper) {
MappingLdifReader bean = new MappingLdifReader();
bean.setResource(new FileSystemResource("src/test/resources/missing.ldif"));
bean.setRecordsToSkip(1);
bean.setRecordMapper(recordMapper);
return bean;
}

@Bean("itemWriter")
public FlatFileItemWriter itemWriter() {
FlatFileItemWriter bean = new FlatFileItemWriter();
bean.setResource(new FileSystemResource("target/test-outputs/output.ldif"));
bean.setLineAggregator(new LdifAggregator());
return bean;
}

@Bean("jobRepository")
public MapJobRepositoryFactoryBean jobRepository(
@Qualifier("transactionManager") ResourcelessTransactionManager transactionManager) {
MapJobRepositoryFactoryBean bean = new MapJobRepositoryFactoryBean();
bean.setTransactionManager(transactionManager);
return bean;
}

@Bean("recordMapper")
public MyMapper recordMapper() {
return new MyMapper();
}

}
Original file line number Diff line number Diff line change
@@ -1,57 +1,33 @@
<?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:batch="http://www.springframework.org/schema/batch"
xsi:schemaLocation="http://www.springframework.org/schema/beans https://www.springframework.org/schema/beans/spring-beans.xsd
http://www.springframework.org/schema/batch https://www.springframework.org/schema/batch/spring-batch-2.0.xsd">

<batch:job id="job">
<batch:step id="step1" next="step2">
<batch:tasklet transaction-manager="transactionManager">
<batch:chunk reader="itemReader1" writer="itemWriter" commit-interval="2" skip-limit="1">
<batch:skippable-exception-classes>org.springframework.ldap.ldif.InvalidAttributeFormatException</batch:skippable-exception-classes>
</batch:chunk>
</batch:tasklet>
</batch:step>
<batch:step id="step2">
<batch:tasklet transaction-manager="transactionManager">
<batch:chunk reader="itemReader2" writer="itemWriter" commit-interval="2" />
</batch:tasklet>
</batch:step>
</batch:job>

<bean id="itemReader1" class="org.springframework.ldap.ldif.batch.MappingLdifReader">
<property name="resource" value="file:src/test/resources/test.ldif" />
<property name="recordsToSkip" value="1" />
<property name="recordMapper" ref="recordMapper" />
</bean>

<bean id="itemReader2" class="org.springframework.ldap.ldif.batch.MappingLdifReader">
<property name="resource" value="file:src/test/resources/missing.ldif" />
<property name="recordsToSkip" value="1" />
<property name="recordMapper" ref="recordMapper" />
</bean>

<bean id="recordMapper" class="org.springframework.ldap.ldif.batch.MyMapper" />

<bean id="itemWriter" class="org.springframework.batch.item.file.FlatFileItemWriter">
<property name="resource" value="file:target/test-outputs/output.ldif" />
<property name="lineAggregator">
<bean class="org.springframework.ldap.ldif.batch.LdifAggregator" />
</property>
</bean>

<bean id="jobLauncher" class="org.springframework.batch.core.launch.support.SimpleJobLauncher">
<property name="jobRepository" ref="jobRepository" />
<property name="taskExecutor" ref="taskExecutor" />
</bean>

<bean id="jobRepository" class="org.springframework.batch.core.repository.support.MapJobRepositoryFactoryBean">
<property name="transactionManager" ref="transactionManager"/>
</bean>

<bean id="transactionManager" class="org.springframework.batch.support.transaction.ResourcelessTransactionManager" />

<bean id="taskExecutor" class="org.springframework.core.task.SyncTaskExecutor" />

</beans>
<?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:batch="http://www.springframework.org/schema/batch"
xsi:schemaLocation="http://www.springframework.org/schema/beans
https://www.springframework.org/schema/beans/spring-beans.xsd
http://www.springframework.org/schema/batch
https://www.springframework.org/schema/batch/spring-batch-2.0.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context.xsd"
xmlns:context="http://www.springframework.org/schema/context">
<batch:job id="job">
<batch:step id="step1" next="step2">
<batch:tasklet transaction-manager="transactionManager">
<batch:chunk reader="itemReader1"
writer="itemWriter"
commit-interval="2"
skip-limit="1">
<batch:skippable-exception-classes>org.springframework.ldap.ldif.InvalidAttributeFormatException</batch:skippable-exception-classes>
</batch:chunk>
</batch:tasklet>
</batch:step>
<batch:step id="step2">
<batch:tasklet transaction-manager="transactionManager">
<batch:chunk reader="itemReader2" writer="itemWriter" commit-interval="2"/>
</batch:tasklet>
</batch:step>
</batch:job>
<context:annotation-config/>
<bean class="org.springframework.ldap.configuration.Batch20ApplicationContextTest2"/>
<bean id="transactionManager"
class="org.springframework.batch.support.transaction.ResourcelessTransactionManager"/>
</beans>
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
/*
* Copyright 2005-2013 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.springframework.ldap.configuration;

import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.ldap.core.LdapTemplate;
import org.springframework.ldap.samples.odm.dao.OdmPersonDaoImpl;
import org.springframework.ldap.samples.utils.LdapTreeBuilder;


/**
* Generated Java based configuration
*
*/
@Configuration
public class ApplicationContext {


@Bean("personDao")
public OdmPersonDaoImpl personDao(
@Qualifier("ldapTemplate")
LdapTemplate ldapTemplate) {
OdmPersonDaoImpl bean = new OdmPersonDaoImpl();
bean.setLdapTemplate(ldapTemplate);
return bean;
}

@Bean("ldapTreeBuilder")
public LdapTreeBuilder ldapTreeBuilder(
@Qualifier("ldapTemplate")
LdapTemplate ldapTemplate) {
return new LdapTreeBuilder(ldapTemplate);
}

}
Loading