java类org.springframework.stereotype.Component的实例源码

PrivateConstructorTest.java 文件源码 项目:EasyFXML 阅读 22 收藏 0 点赞 0 评论 0
@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("[*]");
        });
}
ManagerStructure.java 文件源码 项目:spring-data-generator 阅读 18 收藏 0 点赞 0 评论 0
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);

    }
AutoFormBuilder.java 文件源码 项目:bdf2 阅读 16 收藏 0 点赞 0 评论 0
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;
            }
        }
    }
}
ContainerBuilder.java 文件源码 项目:bdf2 阅读 16 收藏 0 点赞 0 评论 0
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;
            }
        }
    }
}
ContainerBuilder.java 文件源码 项目:bdf2 阅读 16 收藏 0 点赞 0 评论 0
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;
            }
        }
    }
}
ClassReloaderImpl.java 文件源码 项目:tephra 阅读 15 收藏 0 点赞 0 评论 0
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;
}
GroovyScriptFactoryTests.java 文件源码 项目:spring4-understanding 阅读 20 收藏 0 点赞 0 评论 0
@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));
}
AnnotationUtilsTests.java 文件源码 项目:spring4-understanding 阅读 24 收藏 0 点赞 0 评论 0
@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());
}
AnnotationMetadataTests.java 文件源码 项目:spring4-understanding 阅读 23 收藏 0 点赞 0 评论 0
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());
}
AnnotationMetadataTests.java 文件源码 项目:spring4-understanding 阅读 23 收藏 0 点赞 0 评论 0
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));
}
PropertyMappingContextCustomizer.java 文件源码 项目:https-github.com-g0t4-jenkins2-course-spring-boot 阅读 17 收藏 0 点赞 0 评论 0
@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;
}
SingularServerSpringMockitoTestConfig.java 文件源码 项目:singular-server 阅读 25 收藏 0 点赞 0 评论 0
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)
        );
    }
}
PropertyMappingContextCustomizer.java 文件源码 项目:spring-boot-concourse 阅读 17 收藏 0 点赞 0 评论 0
@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;
}
MoebooruViewer.java 文件源码 项目:moebooru-viewer 阅读 28 收藏 0 点赞 0 评论 0
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);
                }
            }
        });
    });
}
MapperScannerConfigurerTest.java 文件源码 项目:mybatis-spring-1.2.2 阅读 18 收藏 0 点赞 0 评论 0
@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");
}
ConfigurationManagerImpl.java 文件源码 项目:zstack 阅读 20 收藏 0 点赞 0 评论 0
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);
            }
        }
    }
}
ConfigurationManagerImpl.java 文件源码 项目:zstack 阅读 28 收藏 0 点赞 0 评论 0
private void generateInventoryPythonClass(StringBuilder sb, List<String> basePkgs) {
    List<String> inventoryPython = new ArrayList<>();
    ClassPathScanningCandidateComponentProvider scanner = new ClassPathScanningCandidateComponentProvider(false);
    scanner.addIncludeFilter(new AnnotationTypeFilter(PythonClassInventory.class));
    scanner.addExcludeFilter(new AnnotationTypeFilter(Component.class));
    for (String pkg : basePkgs) {
        for (BeanDefinition bd : scanner.findCandidateComponents(pkg).stream().sorted((bd1, bd2) -> {
            return bd1.getBeanClassName().compareTo(bd2.getBeanClassName());
        }).collect(Collectors.toList())) {
            try {
                Class<?> clazz = Class.forName(bd.getBeanClassName());
                if (isPythonClassGenerated(clazz)) {
                    /* This class was generated as other's parent class */
                    continue;
                }
                inventoryPython.add(classToInventoryPythonClass(clazz));
            } catch (Exception e) {
                logger.warn(String.format("Unable to generate python class for %s", bd.getBeanClassName()), e);
            }
        }
    }

    for (String invstr : inventoryPython) {
        sb.append(invstr);
    }
}
Commons.java 文件源码 项目:spring-dynamic 阅读 29 收藏 0 点赞 0 评论 0
public static String getBeanName(Class<?> beanClass) {
    String beanName = null;
    Named nameAnn = beanClass.getAnnotation(Named.class);
    //todo 如果没有named标注,则不加入bean;
    if (nameAnn != null) {
        if (Utils.hasLength(nameAnn.value()))
            beanName = nameAnn.value();
    }
    else {
        Component componentAnn = beanClass.getAnnotation(Component.class);
        if (componentAnn != null) {
            if (Utils.hasLength(componentAnn.value()))
                beanName = componentAnn.value();
        }
    }

    if (!Utils.hasLength(beanName)) {
        beanName = Utils.beanName(beanClass.getSimpleName());
    }
    return beanName;
}
StyleProfilePanel.java 文件源码 项目:swing 阅读 16 收藏 0 点赞 0 评论 0
private void decorateLabelWithHighestValue(JPanel panel) {
    JLabel labelWithHigestValue = new JLabel("0.0");
    for (java.awt.Component component : panel.getComponents()) {
        if (component instanceof JLabel) {
            JLabel label = (JLabel) component;
            try {
                double value = Double.parseDouble(label.getText());
                if (value > Double.parseDouble(labelWithHigestValue.getText())) {
                    labelWithHigestValue = label;
                }
            } catch (NumberFormatException ignore) {}
        }
    }
    labelWithHigestValue.setOpaque(true);
    labelWithHigestValue.setBackground(Color.lightGray);
}
EntityList.java 文件源码 项目:swing 阅读 18 收藏 0 点赞 0 评论 0
@Override
@SuppressWarnings("unchecked")
public java.awt.Component getListCellRendererComponent(JList list,
                                                       Object value,
                                                       int index,
                                                       boolean isSelected,
                                                       boolean cellHasFocus) {
    E entity = (E) entityListModel.getElementAt(index);
    if (entity != null && entity.toString() != null && !entity.toString().isEmpty()) {
        setText(entity.toString());
    } else {
        setText("");
    }
    if (entityIcon != null) {
        setIcon(entityIcon);
    }
    if (isSelected) {
        setBackground(list.getSelectionBackground());
        setForeground(list.getSelectionForeground());
    } else {
        setBackground(list.getBackground());
        setForeground(list.getForeground());
    }
    return this;
}
ReturnsSummaryTable.java 文件源码 项目:swing 阅读 18 收藏 0 点赞 0 评论 0
public java.awt.Component getTableCellRendererComponent(JTable table,
                                                        Object value,
                                                        boolean isSelected,
                                                        boolean hasFocus,
                                                        int row,
                                                        int column) {
    if (isSelected) {
        setForeground(table.getSelectionForeground());
        setBackground(table.getSelectionBackground());
    } else {
        setForeground(table.getForeground());
        setBackground(table.getBackground());
    }
    if (row == table.getSelectedRow() && column == table.getSelectedColumn()) {
        setBorder(selectedBorder);       
    } else {
        setBorder(defaultBorder);
    }
    setText((value == null) ? "" : value.toString());
    return this;
}
ReturnsSummaryTable.java 文件源码 项目:swing 阅读 18 收藏 0 点赞 0 评论 0
@Override
public java.awt.Component getTableCellRendererComponent(JTable table,
                                                        Object value,
                                                        boolean isSelected,
                                                        boolean hasFocus,
                                                        int row,
                                                        int column) {
    String text = value.toString();
    setText(text + " ");
    if (isSelected) {
        setBackground(table.getSelectionBackground());
        setForeground(table.getSelectionForeground());
    } else {
        setBackground(table.getBackground());
        setForeground(table.getForeground());
    }
    return this;
}
BenchmarkPortfolioStatisticsTable.java 文件源码 项目:swing 阅读 16 收藏 0 点赞 0 评论 0
@Override
public java.awt.Component getTableCellRendererComponent(JTable table,
                                                        Object value,
                                                        boolean isSelected,
                                                        boolean hasFocus,
                                                        int row,
                                                        int column) {
    setForeground(Color.black);
    String category = (String) value;
    setText(category);
    if (categories.contains(category) || category.isEmpty()) {
        setBackground(Colors.tableRowColor);
    } else {
        setBackground(Color.white);
    }
    if (isSelected) {
        setBackground(Colors.navy);
        setForeground(Color.white);
    }
    return this;
}
StockTable.java 文件源码 项目:swing 阅读 15 收藏 0 点赞 0 评论 0
@Override
public java.awt.Component getTableCellRendererComponent(JTable table,
                                                        Object value,
                                                        boolean isSelected,
                                                        boolean hasFocus,
                                                        int row,
                                                        int column) {
    String text = value.toString();
    try {
        Double.parseDouble(text);
        setHorizontalAlignment(JLabel.RIGHT);
        setText(text + " ");
    } catch (NumberFormatException e) {
        setHorizontalAlignment(JLabel.LEFT);
        setText(text);
    }
    if (isSelected) {
        setBackground(table.getSelectionBackground());
        setForeground(table.getSelectionForeground());
    } else {
        setBackground(table.getBackground());
        setForeground(table.getForeground());
    }
    return this;
}
RegimeComboBox.java 文件源码 项目:swing 阅读 18 收藏 0 点赞 0 评论 0
@Override
public java.awt.Component getListCellRendererComponent(JList list,
                                                             Object value,
                                                             int index,
                                                             boolean isSelected,
                                                             boolean cellHasFocus) {
          Regime regime = (Regime) value;
          setText(regime.getName());
          if (isSelected) {
              setBackground(list.getSelectionBackground());
              setForeground(list.getSelectionForeground());
          } else {
              setBackground(list.getBackground());
              setForeground(list.getForeground());
          }
          return this;
      }
ClassUtilTest.java 文件源码 项目:SocialDataImporter 阅读 19 收藏 0 点赞 0 评论 0
/**
 * Test method for {@link ch.sdi.core.util.ClassUtil#findCandidatesByAnnotation(java.lang.Class, java.lang.String)}.
 */
@Test
public void testFindCandidatesByAnnotationAndType()
{
    myLog.debug( "we parse all classes which are below the top level package" );
    String pack = this.getClass().getPackage().getName();
    myLog.debug( "found package: " + pack );
    pack = pack.replace( '.', '/' );
    String root = pack.split( "/" )[0];

    Collection<? extends Class<?>> received = ClassUtil.findCandidatesByAnnotation( ConverterFactory.class,
                                                                                    Component.class,
                                                                                    root );

    Assert.assertNotNull( received );
    Assert.assertEquals( 1, received.size() );
    received.forEach( c -> myLog.debug( "Found class with annotation @Component and type 'ConverterFactory': "
                + c.getName() ) );

}
GroovyScriptFactoryTests.java 文件源码 项目:class-guard 阅读 24 收藏 0 点赞 0 评论 0
@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));
}
MapperScannerConfigurerTest.java 文件源码 项目:mybatis-spring 阅读 17 收藏 0 点赞 0 评论 0
@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");
}
SpringBeanFactory.java 文件源码 项目:super-csv-annotation 阅读 26 收藏 0 点赞 0 评论 0
private String getBeanName(final Class<?> clazz) {

    final Component componentAnno = clazz.getAnnotation(Component.class);
    if(componentAnno != null && !componentAnno.value().isEmpty()) {
        return componentAnno.value();
    }

    final Service serviceAnno = clazz.getAnnotation(Service.class);
    if(serviceAnno != null && !serviceAnno.value().isEmpty()) {
        return serviceAnno.value();
    }

    final Repository repositoryAnno = clazz.getAnnotation(Repository.class);
    if(repositoryAnno != null && !repositoryAnno.value().isEmpty()) {
        return repositoryAnno.value();
    }

    final Controller controllerAnno = clazz.getAnnotation(Controller.class);
    if(controllerAnno != null && !controllerAnno.value().isEmpty()) {
        return controllerAnno.value();
    }

    // ステレオタイプのアノテーションでBean名の指定がない場合は、クラス名の先頭を小文字にした名称とする。
    return uncapitalize(clazz.getSimpleName());
}
SpringReloader.java 文件源码 项目:parkingfriends 阅读 24 收藏 0 点赞 0 评论 0
private Annotation getSpringClassAnnotation(Class clazz) {
    Annotation classAnnotation = AnnotationUtils.findAnnotation(clazz, Component.class);

    if (classAnnotation == null) {
        classAnnotation = AnnotationUtils.findAnnotation(clazz, Controller.class);
    }
    if (classAnnotation == null) {
        classAnnotation = AnnotationUtils.findAnnotation(clazz, RestController.class);
    }
    if (classAnnotation == null) {
        classAnnotation = AnnotationUtils.findAnnotation(clazz, Service.class);
    }
    if (classAnnotation == null) {
        classAnnotation = AnnotationUtils.findAnnotation(clazz, Repository.class);
    }

    return classAnnotation;
}


问题


面经


文章

微信
公众号

扫码关注公众号