Skip to content
Closed
Show file tree
Hide file tree
Changes from 1 commit
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
Prev Previous commit
Next Next commit
Always store @componentscan details
Refactor JpaComponentScanDetector to a more general use utility and
ensure that details are always stored.
  • Loading branch information
philwebb committed Jun 12, 2013
commit 2f84df66b66567b242be46578f09ca1743888e7b
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
/*
* Copyright 2012-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
*
* http://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.bootstrap.autoconfigure;

import java.util.ArrayList;
import java.util.Collections;
import java.util.List;

import org.springframework.beans.factory.BeanFactory;
import org.springframework.beans.factory.NoSuchBeanDefinitionException;
import org.springframework.beans.factory.config.ConfigurableListableBeanFactory;

/**
* Convenience class for storing base packages during component scan, for reference later
* (e.g. by JPA entity scanner).
*
* @author Phil Webb
* @author Dave Syer
*/
public abstract class AutoConfigurationUtils {

private static String BASE_PACKAGES_BEAN = AutoConfigurationUtils.class.getName()
+ ".basePackages";

@SuppressWarnings("unchecked")
public static List<String> getBasePackages(BeanFactory beanFactory) {
try {
return beanFactory.getBean(BASE_PACKAGES_BEAN, List.class);
} catch (NoSuchBeanDefinitionException e) {
return Collections.emptyList();
}
}

public static void storeBasePackages(ConfigurableListableBeanFactory beanFactory,
List<String> basePackages) {
if (!beanFactory.containsBean(BASE_PACKAGES_BEAN)) {
beanFactory.registerSingleton(BASE_PACKAGES_BEAN, new ArrayList<String>(
basePackages));
} else {
List<String> packages = getBasePackages(beanFactory);
for (String pkg : basePackages) {
if (packages.contains(pkg)) {
packages.add(pkg);
}
}
}
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
* limitations under the License.
*/

package org.springframework.bootstrap.autoconfigure.orm.jpa;
package org.springframework.bootstrap.context.annotation;

import java.io.IOException;
import java.util.ArrayList;
Expand All @@ -31,8 +31,7 @@
import org.springframework.beans.factory.config.ConfigurableListableBeanFactory;
import org.springframework.beans.factory.support.AbstractBeanDefinition;
import org.springframework.beans.factory.support.BeanDefinitionRegistry;
import org.springframework.bootstrap.autoconfigure.data.JpaRepositoriesAutoConfiguration;
import org.springframework.bootstrap.context.annotation.AutoConfigurationUtils;
import org.springframework.bootstrap.autoconfigure.AutoConfigurationUtils;
import org.springframework.cglib.proxy.Enhancer;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.ImportBeanDefinitionRegistrar;
Expand All @@ -48,11 +47,13 @@
/**
* Helper to detect a component scan declared in the enclosing context (normally on a
* {@code @Configuration} class). Once the component scan is detected, the base packages
* are stored for retrieval later by the {@link JpaRepositoriesAutoConfiguration} .
* are stored for retrieval later.
*
* @author Dave Syer
* @author Phillip Webb
* @see AutoConfigurationUtils
*/
class JpaComponentScanDetector implements ImportBeanDefinitionRegistrar, BeanFactoryAware {
class ComponentScanDetector implements ImportBeanDefinitionRegistrar, BeanFactoryAware {

private final Log logger = LogFactory.getLog(getClass());

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
/*
* Copyright 2012-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
*
* http://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.bootstrap.context.annotation;

import org.springframework.context.annotation.Import;

/**
* Simple configuration to import {@link ComponentScanDetector} for tests.
*
* @author Phillip Webb
*/
@Import(ComponentScanDetector.class)
public class ComponentScanDetectorConfiguration {

}