org.springframework.boot.autoconfigure.SpringBootApplication Java Examples

The following examples show how to use org.springframework.boot.autoconfigure.SpringBootApplication. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: ModuleTestExecution.java    From moduliths with Apache License 2.0 7 votes vote down vote up
public static java.util.function.Supplier<ModuleTestExecution> of(Class<?> type) {

		return () -> {

			ModuleTest annotation = AnnotatedElementUtils.findMergedAnnotation(type, ModuleTest.class);
			String packageName = type.getPackage().getName();

			Class<?> modulithType = MODULITH_TYPES.computeIfAbsent(type,
					it -> new AnnotatedClassFinder(SpringBootApplication.class).findFromPackage(packageName));
			Modules modules = Modules.of(modulithType);
			Module module = modules.getModuleForPackage(packageName) //
					.orElseThrow(
							() -> new IllegalStateException(String.format("Package %s is not part of any module!", packageName)));

			return EXECUTIONS.computeIfAbsent(Key.of(module.getBasePackage().getName(), annotation),
					it -> new ModuleTestExecution(annotation, modules, module));
		};
	}
 
Example #2
Source File: GenUtil.java    From albedo with GNU Lesser General Public License v3.0 6 votes vote down vote up
/**
 * 获取数据模型
 *
 * @param scheme
 * @return
 */
public static Map<String, Object> getDataModel(SchemeDto scheme) {
	Map<String, Object> model = Maps.newHashMap();
	String applicationName = SpringContextHolder.getApplicationContext().getBeansWithAnnotation(SpringBootApplication.class).keySet().iterator().next();
	model.put("applicationName", SpringContextHolder.getApplicationContext().getBean(applicationName).getClass().getPackage().getName() + StringUtil.DOT + StringUtil.upperFirst(applicationName));
	model.put("packageName", StringUtil.lowerCase(scheme.getPackageName()));
	model.put("lastPackageName", StringUtil.subAfter((String) model.get("packageName"), StringUtil.DOT, true));
	model.put("moduleName", StringUtil.lowerCase(scheme.getModuleName()));
	model.put("subModuleName", StringUtil.lowerCase(StringUtil.isEmpty(scheme.getSubModuleName()) ? "" : scheme.getSubModuleName()));
	model.put("className", StringUtil.lowerFirst(scheme.getTableDto().getClassName()));
	model.put("classNameUrl", StringUtil.toRevertCamelCase(StringUtil.toStrString(model.get("className")), CharUtil.DASHED));
	model.put("ClassName", StringUtil.upperFirst(scheme.getTableDto().getClassName()));

	model.put("functionName", scheme.getFunctionName());
	model.put("functionNameSimple", scheme.getFunctionNameSimple());
	model.put("functionAuthor", StringUtil.isNotBlank(scheme.getFunctionAuthor()) ? scheme.getFunctionAuthor() : "");
	model.put("functionVersion", DateUtil.now());
	model.put("urlPrefix", model.get("moduleName") + (StringUtil.isNotBlank(scheme.getSubModuleName()) ? StringUtil.SLASH +
		StringUtil.lowerCase(scheme.getSubModuleName()) : "") + StringUtil.SLASH + model.get("classNameUrl")
	);
	model.put("viewPrefix", model.get("urlPrefix"));
	model.put("permissionPrefix", model.get("moduleName") + (StringUtil.isNotBlank(scheme.getSubModuleName()) ? "_" + StringUtil.lowerCase(scheme.getSubModuleName()) : "") + "_" + model.get("className"));
	model.put("table", scheme.getTableDto());
	model.put("scheme", scheme);
	return model;
}
 
Example #3
Source File: SwaggerConfig.java    From summerframework with Apache License 2.0 5 votes vote down vote up
@Bean
public Docket docket() {
    ArrayList<String> basePackage=new ArrayList<>();
    if(!StringUtils.isEmpty(swaggerBasePackage)){
        basePackage.addAll(Arrays.asList(swaggerBasePackage.split(",")));
    }else {
        // 从注解中解析basePackage
        Map<String, Object> applicationClass = applicationContext.getBeansWithAnnotation(SpringBootApplication.class);
        if(applicationClass.size()>1){
            log.warn("{} SpringBootApplication : {}",applicationClass.size(),applicationClass);
        }
        applicationClass.forEach((k,v)->{
            SpringBootApplication ann = AnnotationUtils.findAnnotation(v.getClass(), SpringBootApplication.class);
            if(ann.scanBasePackages().length==0&&ann.scanBasePackageClasses().length==0){
                basePackage.add(v.getClass().getPackage().getName());
            }else {
                basePackage.addAll(Arrays.asList(ann.scanBasePackages()));
                basePackage.addAll(Arrays.asList(ann.scanBasePackageClasses()).stream().map(s->s.getPackage().getName()).collect(Collectors.toList()));
            }
        });
    }
    return new Docket(DocumentationType.SWAGGER_2).select().apis(Predicates.or(basePackage.stream().map(RequestHandlerSelectors::basePackage).collect(Collectors.toList())))
        .paths(Predicates.not(PathSelectors.regex("/error.*"))).build()
        .apiInfo(new ApiInfo(configurableEnvironment.getProperty("spring.application.name"), "",
            configurableEnvironment.getProperty("spring.application.version"), "",
            new Contact(configurableEnvironment.getProperty("spring.application.contact"), "", ""), "", "",
            new ArrayList<>()));
}
 
Example #4
Source File: ModulithMetadataUnitTest.java    From moduliths with Apache License 2.0 5 votes vote down vote up
@Test // #72
public void rejectsTypeNotAnnotatedWithEitherModulithAnnotationOrSpringBootApplication() {

	assertThatExceptionOfType(IllegalArgumentException.class) //
			.isThrownBy(() -> ModulithMetadata.of(Unannotated.class)) //
			.withMessageContaining(Modulith.class.getSimpleName()) //
			.withMessageContaining(Modulithic.class.getSimpleName()) //
			.withMessageContaining(SpringBootApplication.class.getSimpleName());
}
 
Example #5
Source File: SpringPackageVersionResolver.java    From kork with Apache License 2.0 5 votes vote down vote up
@Nullable
@Override
public String resolve(@Nonnull String serviceName) {
  Map<String, Object> annotatedBeans =
      applicationContext.getBeansWithAnnotation(SpringBootApplication.class);
  return annotatedBeans.isEmpty()
      ? null
      : annotatedBeans.values().toArray()[0].getClass().getPackage().getImplementationVersion();
}
 
Example #6
Source File: FunctionClassUtils.java    From spring-cloud-function with Apache License 2.0 4 votes vote down vote up
private static boolean isSpringBootApplication(Class<?> startClass) {
	return startClass.getDeclaredAnnotation(SpringBootApplication.class) != null
			|| startClass.getDeclaredAnnotation(SpringBootConfiguration.class) != null;
}
 
Example #7
Source File: ClassCandidateScanner.java    From wicket-spring-boot with Apache License 2.0 4 votes vote down vote up
@PostConstruct
public void postConstruct() {
	ClassPathScanningCandidateComponentProvider scanner = new ClassPathScanningCandidateComponentProvider(
			false);
	scanner.setEnvironment(this.environment);
	scanner.setResourceLoader(this.resourceLoader);
	scanner.addIncludeFilter(new AnnotationTypeFilter(SpringBootApplication.class));
	scanner.addIncludeFilter(new AnnotationTypeFilter(WicketHomePage.class));
	scanner.addIncludeFilter(new AnnotationTypeFilter(WicketSignInPage.class));
    scanner.addIncludeFilter(new AnnotationTypeFilter(WicketAccessDeniedPage.class));
    scanner.addIncludeFilter(new AnnotationTypeFilter(WicketExpiredPage.class));
    scanner.addIncludeFilter(new AnnotationTypeFilter(WicketInternalErrorPage.class));
    for (String basePackage : getMappingBasePackages(beanFactory)) {
		if (StringUtils.hasText(basePackage)) {
			pageCandidates().getBasePackages().add(basePackage);
			Set<BeanDefinition> beanDefinitions = scanner.findCandidateComponents(basePackage);
			for (BeanDefinition beanDefinition : beanDefinitions) {
				Class<?> beanClass;
				try {
					beanClass = ClassUtils.forName(beanDefinition.getBeanClassName(), classLoader);
				} catch (ClassNotFoundException e) {
					throw new IllegalStateException(e);
				}
				if(beanClass.isAnnotationPresent(WicketHomePage.class)){
					pageCandidates().getHomePageCandidates().add(new WicketClassCandidate<Page>((Class<Page>) beanClass));
				}
				if(beanClass.isAnnotationPresent(WicketSignInPage.class)){
					pageCandidates().getSignInPageCandidates().add(new WicketClassCandidate<WebPage>((Class<WebPage>) beanClass));
				}
				if(beanClass.isAnnotationPresent(WicketAccessDeniedPage.class)){
					pageCandidates().getAccessDeniedPageCandidates().add(new WicketClassCandidate<Page>((Class<Page>) beanClass));
				}
				if(beanClass.isAnnotationPresent(WicketExpiredPage.class)){
					pageCandidates().getExpiredPageCandidates().add(new WicketClassCandidate<Page>((Class<Page>) beanClass));
				}
				if(beanClass.isAnnotationPresent(WicketInternalErrorPage.class)){
					pageCandidates().getInternalErrorPageCandidates().add(new WicketClassCandidate<Page>((Class<Page>) beanClass));
				}
				if(beanClass.isAnnotationPresent(SpringBootApplication.class)){
					pageCandidates().setSpringBootMainClass( beanClass );
				}
			}
			
		}
    }
}
 
Example #8
Source File: SpringApplicationParser.java    From typescript-generator with MIT License 4 votes vote down vote up
@Override
public JaxrsApplicationParser.Result tryParse(SourceType<?> sourceType) {
    if (!(sourceType.type instanceof Class<?>)) {
        return null;
    }
    final Class<?> cls = (Class<?>) sourceType.type;

    // application
    final SpringBootApplication app = AnnotationUtils.findAnnotation(cls, SpringBootApplication.class);
    if (app != null) {
        if (settings.scanSpringApplication) {
            TypeScriptGenerator.getLogger().verbose("Scanning Spring application: " + cls.getName());
            final ClassLoader originalContextClassLoader = Thread.currentThread().getContextClassLoader();
            try {
                Thread.currentThread().setContextClassLoader(settings.classLoader);
                final SpringApplicationHelper springApplicationHelper = new SpringApplicationHelper(settings.classLoader, cls);
                final List<Class<?>> restControllers = springApplicationHelper.findRestControllers();
                return new JaxrsApplicationParser.Result(restControllers.stream()
                    .map(controller -> new SourceType<Type>(controller, cls, "<scanned>"))
                    .collect(Collectors.toList())
                );
            } finally {
                Thread.currentThread().setContextClassLoader(originalContextClassLoader);
            }
        } else {
            return null;
        }
    }

    // controller
    final Component component = AnnotationUtils.findAnnotation(cls, Component.class);
    if (component != null) {
        TypeScriptGenerator.getLogger().verbose("Parsing Spring component: " + cls.getName());
        final JaxrsApplicationParser.Result result = new JaxrsApplicationParser.Result();
        final RequestMapping requestMapping = AnnotatedElementUtils.findMergedAnnotation(cls, RequestMapping.class);
        final String path = requestMapping != null && requestMapping.path() != null && requestMapping.path().length != 0 ? requestMapping.path()[0] : null;
        final JaxrsApplicationParser.ResourceContext context = new JaxrsApplicationParser.ResourceContext(cls, path);
        parseController(result, context, cls);
        return result;
    }

    return null;
}