當前位置: 首頁>>代碼示例>>Java>>正文


Java Component類代碼示例

本文整理匯總了Java中org.springframework.stereotype.Component的典型用法代碼示例。如果您正苦於以下問題:Java Component類的具體用法?Java Component怎麽用?Java Component使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


Component類屬於org.springframework.stereotype包,在下文中一共展示了Component類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: getBeanName

import org.springframework.stereotype.Component; //導入依賴的package包/類
private String getBeanName(Class<?> clazz) {
    Component component = clazz.getAnnotation(Component.class);
    if (component != null)
        return component.value();

    Repository repository = clazz.getAnnotation(Repository.class);
    if (repository != null)
        return repository.value();

    Service service = clazz.getAnnotation(Service.class);
    if (service != null)
        return service.value();

    Controller controller = clazz.getAnnotation(Controller.class);
    if (controller != null)
        return controller.value();

    return null;
}
 
開發者ID:heisedebaise,項目名稱:tephra,代碼行數:20,代碼來源:ClassReloaderImpl.java

示例2: assertExistsPrivateCtor

import org.springframework.stereotype.Component; //導入依賴的package包/類
@Test
public void assertExistsPrivateCtor() {
    reflections.getSubTypesOf(Object.class).stream()
        .filter(clazz -> !clazz.isAnnotationPresent(Configuration.class))
        .filter(clazz -> !clazz.isAnnotationPresent(Component.class))
        .filter(clazz -> !clazz.isAnnotationPresent(SpringBootApplication.class))
        .filter(clazz -> !clazz.getName().endsWith("Test"))
        .filter(clazz -> !clazz.isInterface())
        .filter(clazz ->
            Arrays.stream(clazz.getDeclaredFields())
                .allMatch(field -> Modifier.isStatic(field.getModifiers())))
        .forEach(clazz -> {
            System.out.println("Expecting class "+clazz.getName()+" to :");
            System.out.print("\t-> be final ");
            assertThat(clazz).isFinal();
            System.out.println("[*]");
            System.out.print("\t-> have exactly one constructor ");
            Constructor<?>[] constructors = clazz.getDeclaredConstructors();
            assertThat(constructors).hasSize(1);
            System.out.println("[*]");
            System.out.print("\t-> and that this constructor is private ");
            assertThat(Modifier.isPrivate(constructors[0].getModifiers()));
            System.out.println("[*]");
        });
}
 
開發者ID:Tristan971,項目名稱:EasyFXML,代碼行數:26,代碼來源:PrivateConstructorTest.java

示例3: ManagerStructure

import org.springframework.stereotype.Component; //導入依賴的package包/類
public ManagerStructure(String managerPackage, String entityName, String postfix, String repositoryPackage, String repositoryPostfix) {

        String managerName = entityName + postfix;
        String repositoryName = entityName + repositoryPostfix;
        String repositoryNameAttribute = GeneratorUtils.decapitalize(repositoryName);

        this.objectBuilder = new ObjectBuilder(new ObjectStructure(managerPackage, ScopeValues.PUBLIC, ObjectTypeValues.CLASS, managerName)
                .addImport(repositoryPackage + "." + repositoryName)
                .addImport(Autowired.class)
                .addImport(Component.class)
                .addAnnotation(Component.class)
                .addAttribute(repositoryName, repositoryNameAttribute)
                .addConstructor(new ObjectStructure.ObjectConstructor(ScopeValues.PUBLIC, managerName)
                        .addAnnotation(Autowired.class)
                        .addArgument(repositoryName, repositoryNameAttribute)
                        .addBodyLine(ObjectValues.THIS.getValue() + repositoryNameAttribute + ExpressionValues.EQUAL.getValue() + repositoryNameAttribute)
                )
        ).setAttributeBottom(false);

    }
 
開發者ID:cmeza20,項目名稱:spring-data-generator,代碼行數:21,代碼來源:ManagerStructure.java

示例4: build

import org.springframework.stereotype.Component; //導入依賴的package包/類
public void build(Object control, ViewComponent parentViewComponent) {
	AutoForm autoForm = (AutoForm) control;
	String id = autoForm.getId();
	ViewComponent component = generateViewComponent(id,AutoForm.class);
	if (StringUtils.isEmpty(id)) {
		component.setEnabled(false);
	}
	parentViewComponent.addChildren(component);
	for (com.bstek.dorado.view.widget.Component c : autoForm.getElements()) {
		for (IControlBuilder builder : builders) {
			if (builder.support(c)) {
				builder.build(c, component);
				break;
			}
		}
	}
}
 
開發者ID:bsteker,項目名稱:bdf2,代碼行數:18,代碼來源:AutoFormBuilder.java

示例5: build

import org.springframework.stereotype.Component; //導入依賴的package包/類
public void build(Object control, ViewComponent parentViewComponent) {
	Container container=(Container)control;
	String id=container.getId();
	ViewComponent component=new ViewComponent();
	component.setId(id);
	component.setIcon(">dorado/res/"+Container.class.getName().replaceAll("\\.", "/")+".png");
	component.setName(container.getClass().getSimpleName());
	if(StringUtils.isEmpty(id)){
		component.setEnabled(false);
	}
	parentViewComponent.addChildren(component);
	for(com.bstek.dorado.view.widget.Component c:container.getChildren()){
		for(IControlBuilder builder:builders){
			if(builder.support(c)){
				builder.build(c, component);
				break;
			}
		}
	}
}
 
開發者ID:bsteker,項目名稱:bdf2,代碼行數:21,代碼來源:ContainerBuilder.java

示例6: build

import org.springframework.stereotype.Component; //導入依賴的package包/類
public void build(Object control, ViewComponent parentViewComponent) {
	Container container=(Container)control;
	String id=container.getId();
	ViewComponent component=new ViewComponent();
	component.setId(id);
	component.setIcon(">dorado/res/"+container.getClass().getName().replaceAll("\\.", "/")+".png");
	component.setName(container.getClass().getSimpleName());
	if(StringUtils.isEmpty(id)){
		component.setEnabled(false);
	}
	parentViewComponent.addChildren(component);
	for(com.bstek.dorado.view.widget.Component c:container.getChildren()){
		for(IControlBuilder builder:builders){
			if(builder.support(c)){
				builder.build(c, component);
				break;
			}
		}
	}
}
 
開發者ID:bsteker,項目名稱:bdf2,代碼行數:21,代碼來源:ContainerBuilder.java

示例7: testRefreshableFromTagProxyTargetClass

import org.springframework.stereotype.Component; //導入依賴的package包/類
@Test
// Test for SPR-6268
public void testRefreshableFromTagProxyTargetClass() throws Exception {
	ApplicationContext ctx = new ClassPathXmlApplicationContext("groovy-with-xsd-proxy-target-class.xml",
			getClass());
	assertTrue(Arrays.asList(ctx.getBeanNamesForType(Messenger.class)).contains("refreshableMessenger"));

	Messenger messenger = (Messenger) ctx.getBean("refreshableMessenger");

	assertTrue(AopUtils.isAopProxy(messenger));
	assertTrue(messenger instanceof Refreshable);
	assertEquals("Hello World!", messenger.getMessage());

	assertTrue(ctx.getBeansOfType(ConcreteMessenger.class).values().contains(messenger));

	// Check that AnnotationUtils works with concrete proxied script classes
	assertNotNull(AnnotationUtils.findAnnotation(messenger.getClass(), Component.class));
}
 
開發者ID:langtianya,項目名稱:spring4-understanding,代碼行數:19,代碼來源:GroovyScriptFactoryTests.java

示例8: synthesizeAnnotationFromAnnotationAttributesWithoutAttributeAliases

import org.springframework.stereotype.Component; //導入依賴的package包/類
@Test
public void synthesizeAnnotationFromAnnotationAttributesWithoutAttributeAliases() throws Exception {

	// 1) Get an annotation
	Component component = WebController.class.getAnnotation(Component.class);
	assertNotNull(component);

	// 2) Convert the annotation into AnnotationAttributes
	AnnotationAttributes attributes = getAnnotationAttributes(WebController.class, component);
	assertNotNull(attributes);

	// 3) Synthesize the AnnotationAttributes back into an annotation
	Component synthesizedComponent = synthesizeAnnotation(attributes, Component.class, WebController.class);
	assertNotNull(synthesizedComponent);

	// 4) Verify that the original and synthesized annotations are equivalent
	assertNotSame(component, synthesizedComponent);
	assertEquals(component, synthesizedComponent);
	assertEquals("value from component: ", "webController", component.value());
	assertEquals("value from synthesized component: ", "webController", synthesizedComponent.value());
}
 
開發者ID:langtianya,項目名稱:spring4-understanding,代碼行數:22,代碼來源:AnnotationUtilsTests.java

示例9: doTestSubClassAnnotationInfo

import org.springframework.stereotype.Component; //導入依賴的package包/類
private void doTestSubClassAnnotationInfo(AnnotationMetadata metadata) {
	assertThat(metadata.getClassName(), is(AnnotatedComponentSubClass.class.getName()));
	assertThat(metadata.isInterface(), is(false));
	assertThat(metadata.isAnnotation(), is(false));
	assertThat(metadata.isAbstract(), is(false));
	assertThat(metadata.isConcrete(), is(true));
	assertThat(metadata.hasSuperClass(), is(true));
	assertThat(metadata.getSuperClassName(), is(AnnotatedComponent.class.getName()));
	assertThat(metadata.getInterfaceNames().length, is(0));
	assertThat(metadata.isAnnotated(Component.class.getName()), is(false));
	assertThat(metadata.isAnnotated(Scope.class.getName()), is(false));
	assertThat(metadata.isAnnotated(SpecialAttr.class.getName()), is(false));
	assertThat(metadata.hasAnnotation(Component.class.getName()), is(false));
	assertThat(metadata.hasAnnotation(Scope.class.getName()), is(false));
	assertThat(metadata.hasAnnotation(SpecialAttr.class.getName()), is(false));
	assertThat(metadata.getAnnotationTypes().size(), is(0));
	assertThat(metadata.getAnnotationAttributes(Component.class.getName()), nullValue());
	assertThat(metadata.getAnnotatedMethods(DirectAnnotation.class.getName()).size(), equalTo(0));
	assertThat(metadata.isAnnotated(IsAnnotatedAnnotation.class.getName()), equalTo(false));
	assertThat(metadata.getAllAnnotationAttributes(DirectAnnotation.class.getName()), nullValue());
}
 
開發者ID:langtianya,項目名稱:spring4-understanding,代碼行數:22,代碼來源:AnnotationMetadataTests.java

示例10: doTestMetadataForAnnotationClass

import org.springframework.stereotype.Component; //導入依賴的package包/類
private void doTestMetadataForAnnotationClass(AnnotationMetadata metadata) {
	assertThat(metadata.getClassName(), is(Component.class.getName()));
	assertThat(metadata.isInterface(), is(true));
	assertThat(metadata.isAnnotation(), is(true));
	assertThat(metadata.isAbstract(), is(true));
	assertThat(metadata.isConcrete(), is(false));
	assertThat(metadata.hasSuperClass(), is(false));
	assertThat(metadata.getSuperClassName(), nullValue());
	assertThat(metadata.getInterfaceNames().length, is(1));
	assertThat(metadata.getInterfaceNames()[0], is(Annotation.class.getName()));
	assertThat(metadata.isAnnotated(Documented.class.getName()), is(false));
	assertThat(metadata.isAnnotated(Scope.class.getName()), is(false));
	assertThat(metadata.isAnnotated(SpecialAttr.class.getName()), is(false));
	assertThat(metadata.hasAnnotation(Documented.class.getName()), is(true));
	assertThat(metadata.hasAnnotation(Scope.class.getName()), is(false));
	assertThat(metadata.hasAnnotation(SpecialAttr.class.getName()), is(false));
	assertThat(metadata.getAnnotationTypes().size(), is(3));
}
 
開發者ID:langtianya,項目名稱:spring4-understanding,代碼行數:19,代碼來源:AnnotationMetadataTests.java

示例11: postProcessBeforeInitialization

import org.springframework.stereotype.Component; //導入依賴的package包/類
@Override
public Object postProcessBeforeInitialization(Object bean, String beanName)
		throws BeansException {
	Class<?> beanClass = bean.getClass();
	Set<Class<?>> components = new LinkedHashSet<Class<?>>();
	Set<Class<?>> propertyMappings = new LinkedHashSet<Class<?>>();
	while (beanClass != null) {
		for (Annotation annotation : AnnotationUtils.getAnnotations(beanClass)) {
			if (isAnnotated(annotation, Component.class)) {
				components.add(annotation.annotationType());
			}
			if (isAnnotated(annotation, PropertyMapping.class)) {
				propertyMappings.add(annotation.annotationType());
			}
		}
		beanClass = beanClass.getSuperclass();
	}
	if (!components.isEmpty() && !propertyMappings.isEmpty()) {
		throw new IllegalStateException("The @PropertyMapping "
				+ getAnnotationsDescription(propertyMappings)
				+ " cannot be used in combination with the @Component "
				+ getAnnotationsDescription(components));
	}
	return bean;
}
 
開發者ID:vikrammane23,項目名稱:https-github.com-g0t4-jenkins2-course-spring-boot,代碼行數:26,代碼來源:PropertyMappingContextCustomizer.java

示例12: resetAndReconfigure

import org.springframework.stereotype.Component; //導入依賴的package包/類
public void resetAndReconfigure(boolean debug) {
    SingularContextSetup.reset();
    ApplicationContextMock applicationContext = new ApplicationContextMock();
    ServiceRegistryLocator.setup(new SpringServiceRegistry());
    new ApplicationContextProvider().setApplicationContext(applicationContext);
    registerBeanFactories(applicationContext);
    registerAnnotated(applicationContext, Named.class);
    registerAnnotated(applicationContext, Service.class);
    registerAnnotated(applicationContext, Component.class);
    registerAnnotated(applicationContext, Repository.class);
    registerMockitoTestClassMocksAndSpies(applicationContext);
    getLogger().info("Contexto configurado com os beans: ");
    if (debug) {
        applicationContext.listAllBeans().forEach(
                b -> getLogger().info(b)
        );
    }
}
 
開發者ID:opensingular,項目名稱:singular-server,代碼行數:19,代碼來源:SingularServerSpringMockitoTestConfig.java

示例13: showPostById

import org.springframework.stereotype.Component; //導入依賴的package包/類
public void showPostById(int id, java.awt.Component dialogParent){
    JOptionPane optionPane = new JOptionPane(Localization.format("retrieval_format", String.valueOf(id)), JOptionPane.INFORMATION_MESSAGE);
    JButton button = new JButton(Localization.getString("cancel"));
    optionPane.setOptions(new Object[]{button});
    JDialog dialog = optionPane.createDialog(dialogParent, Localization.getString("retrieving"));
    button.addActionListener(event -> dialog.dispose());
    dialog.setModalityType(ModalityType.MODELESS);
    dialog.setVisible(true);
    executor.execute(() -> {
        List<Post> searchPosts = mapi.listPosts(1, 1, "id:" + id);
        SwingUtilities.invokeLater(() -> {
            if (dialog.isDisplayable()){
                dialog.dispose();
                if (!searchPosts.isEmpty()){
                    showPostFrame.showPost(searchPosts.get(0));
                }else{
                    JOptionPane.showMessageDialog(null, Localization.getString("id_doesnot_exists"),
                        Localization.getString("error"), JOptionPane.ERROR_MESSAGE);
                }
            }
        });
    });
}
 
開發者ID:azige,項目名稱:moebooru-viewer,代碼行數:24,代碼來源:MoebooruViewer.java

示例14: testMarkerInterfaceAndAnnotationScan

import org.springframework.stereotype.Component; //導入依賴的package包/類
@Test
public void testMarkerInterfaceAndAnnotationScan() {
  applicationContext.getBeanDefinition("mapperScanner").getPropertyValues().add(
      "markerInterface", MapperInterface.class);
  applicationContext.getBeanDefinition("mapperScanner").getPropertyValues().add(
      "annotationClass", Component.class);

  startContext();

  // everything should be loaded but the marker interface
  applicationContext.getBean("annotatedMapper");
  applicationContext.getBean("mapperSubinterface");
  applicationContext.getBean("mapperChildInterface");

  assertBeanNotLoaded("mapperInterface");
}
 
開發者ID:lindzh,項目名稱:mybatis-spring-1.2.2,代碼行數:17,代碼來源:MapperScannerConfigurerTest.java

示例15: generateApiMessageGroovyClass

import org.springframework.stereotype.Component; //導入依賴的package包/類
private void generateApiMessageGroovyClass(StringBuilder sb, List<String> basePkgs) {
    ClassPathScanningCandidateComponentProvider scanner = new ClassPathScanningCandidateComponentProvider(true);
    scanner.addIncludeFilter(new AssignableTypeFilter(APIMessage.class));
    scanner.addIncludeFilter(new AssignableTypeFilter(APIReply.class));
    scanner.addIncludeFilter(new AssignableTypeFilter(APIEvent.class));
    scanner.addExcludeFilter(new AnnotationTypeFilter(Controller.class));
    scanner.addExcludeFilter(new AnnotationTypeFilter(Component.class));
    for (String pkg : basePkgs) {
        for (BeanDefinition bd : scanner.findCandidateComponents(pkg)) {
            try {
                Class<?> clazz = Class.forName(bd.getBeanClassName());
                //classToApiMessageGroovyClass(sb, clazz);
                classToApiMessageGroovyInformation(sb, clazz);
            } catch (ClassNotFoundException e) {
                logger.warn(String.format("Unable to generate groovy class for %s", bd.getBeanClassName()), e);
            }
        }
    }
}
 
開發者ID:zstackio,項目名稱:zstack,代碼行數:20,代碼來源:ConfigurationManagerImpl.java


注:本文中的org.springframework.stereotype.Component類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。