当前位置: 首页>>代码示例>>Java>>正文


Java Autowire类代码示例

本文整理汇总了Java中org.springframework.beans.factory.annotation.Autowire的典型用法代码示例。如果您正苦于以下问题:Java Autowire类的具体用法?Java Autowire怎么用?Java Autowire使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


Autowire类属于org.springframework.beans.factory.annotation包,在下文中一共展示了Autowire类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: setEnumProperty

import org.springframework.beans.factory.annotation.Autowire; //导入依赖的package包/类
@Test
public void setEnumProperty() {
	EnumTester target = new EnumTester();
	AbstractPropertyAccessor accessor = createAccessor(target);

	accessor.setPropertyValue("autowire", "BY_NAME");
	assertEquals(Autowire.BY_NAME, target.getAutowire());

	accessor.setPropertyValue("autowire", "  BY_TYPE ");
	assertEquals(Autowire.BY_TYPE, target.getAutowire());

	try {
		accessor.setPropertyValue("autowire", "NHERITED");
		fail("Should have thrown TypeMismatchException");
	}
	catch (TypeMismatchException ex) {
		// expected
	}
}
 
开发者ID:langtianya,项目名称:spring4-understanding,代码行数:20,代码来源:AbstractPropertyAccessorTests.java

示例2: testEnumByFieldName

import org.springframework.beans.factory.annotation.Autowire; //导入依赖的package包/类
@Test
public void testEnumByFieldName() {
	EnumTester et = new EnumTester();
	BeanWrapper bw = new BeanWrapperImpl(et);

	bw.setPropertyValue("autowire", "BY_NAME");
	assertEquals(Autowire.BY_NAME, et.getAutowire());

	bw.setPropertyValue("autowire", "  BY_TYPE ");
	assertEquals(Autowire.BY_TYPE, et.getAutowire());

	try {
		bw.setPropertyValue("autowire", "NHERITED");
		fail("Should have thrown TypeMismatchException");
	}
	catch (TypeMismatchException ex) {
		// expected
	}
}
 
开发者ID:deathspeeder,项目名称:class-guard,代码行数:20,代码来源:BeanWrapperTests.java

示例3: setupIndexMasterActor

import org.springframework.beans.factory.annotation.Autowire; //导入依赖的package包/类
@Bean(autowire = Autowire.BY_NAME, name = "setupIndexMasterActor")
// @Scope("prototype")
@DependsOn(value = { "actorSystem" })
public ActorRef setupIndexMasterActor() {
	final ActorSystem system = applicationContext
			.getBean(ActorSystem.class);
	final SetupIndexService setupIndexService = applicationContext
			.getBean(SetupIndexService.class);
	final SampleDataGeneratorService sampleDataGeneratorService = applicationContext
			.getBean(SampleDataGeneratorService.class);
	final IndexProductDataService indexProductData = applicationContext
			.getBean(IndexProductDataService.class);
	return system.actorOf(
			Props.create(SetupIndexMasterActor.class, setupIndexService,
					sampleDataGeneratorService, indexProductData)
					.withDispatcher("setupIndexMasterActorDispatch"),
			"setupIndexMasterActor");
}
 
开发者ID:jaibeermalik,项目名称:searchanalytics-bigdata,代码行数:19,代码来源:AppConfiguration.java

示例4: instance

import org.springframework.beans.factory.annotation.Autowire; //导入依赖的package包/类
@Bean(autowire = Autowire.BY_TYPE, name = "ctu.upns.groupRepository")
public GroupRepository instance() {

	if (repository != null) {
		return repository;
	}

	switch (type) {
		case "memory":
			repository = new MemGroupRepository();
		case "mongo":
			repository = new MongoGroupRepository();
	}

	Validate.notNull(repository, "invalid repository type:[%s]", type);
	return repository;
}
 
开发者ID:pippo1980,项目名称:upns,代码行数:18,代码来源:GroupRepositoryConfig.java

示例5: instance

import org.springframework.beans.factory.annotation.Autowire; //导入依赖的package包/类
@Bean(autowire = Autowire.BY_TYPE, name = "ctu.upns.deviceRepository")
public DeviceRepository instance() {

	if (repository != null) {
		return repository;
	}

	switch (type) {
		case "memory":
			repository = new MemDeviceRepository();
		case "mongo":
			repository = new MongoDeviceRepository();
	}

	Validate.notNull(repository, "invalid repository type:[%s]", type);
	return repository;
}
 
开发者ID:pippo1980,项目名称:upns,代码行数:18,代码来源:DeviceRepositoryConfig.java

示例6: instance

import org.springframework.beans.factory.annotation.Autowire; //导入依赖的package包/类
@Bean(autowire = Autowire.BY_TYPE, name = "ctu.upns.messageRepository")
public MessageRepository instance() {

	if (repository != null) {
		return repository;
	}

	switch (type) {
		case "memory":
			repository = new MemMessageRepository();
		case "mongo":
			repository = new MongoMessageRepository();
	}

	Validate.notNull(repository, "invalid repository type:[%s]", type);
	return repository;
}
 
开发者ID:pippo1980,项目名称:upns,代码行数:18,代码来源:MessageRepositoryConfig.java

示例7: instance

import org.springframework.beans.factory.annotation.Autowire; //导入依赖的package包/类
@Bean(autowire = Autowire.BY_TYPE, name = "ctu.upns.subscriberManager")
public SubscriberManager instance() {

    if (subscriberManager != null) {
        return subscriberManager;
    }

    switch (service_type) {
        case "memory":
            subscriberManager = new MemSubscriberManager();
            return subscriberManager;
        case "mongo":
            return null;
        default:
            throw new IllegalArgumentException(String.format("invalid service type", service_type));
    }

}
 
开发者ID:pippo1980,项目名称:upns,代码行数:19,代码来源:SubscriberManagerConfig.java

示例8: mailBean

import org.springframework.beans.factory.annotation.Autowire; //导入依赖的package包/类
@Bean(autowire = Autowire.BY_TYPE)
public MailSender mailBean()
{
    JavaMailSenderImpl mailSender = new JavaMailSenderImpl();
    mailSender.setHost(mailHost);
    mailSender.setUsername(mailUserName);
    mailSender.setPassword(mailPassword);
    setUpMailPro(mailSender);

    return mailSender;
}
 
开发者ID:LinuxSuRen,项目名称:phoenix.webui.framework,代码行数:12,代码来源:MailConfig.java

示例9: createSqlBuilder

import org.springframework.beans.factory.annotation.Autowire; //导入依赖的package包/类
/**
 * create  a query builder instance per db type
 *
 * @return query builder instance
 */
@Bean(name = "queryBuilder", autowire = Autowire.BY_TYPE)
public IQueryBuilder createSqlBuilder() throws SQLException {
    JdbcHelper jdbcHelper = beanFactory.getBean(JdbcHelper.class);
    StorageProperties storageProperties = beanFactory.getBean(StorageProperties.class);
    String productName = storageProperties.getDbType().toString();
    Connection connection = jdbcHelper.getDataSource().getConnection();
    connection.close();
    IQueryBuilder queryBuilder;
    switch (productName) {
        case "oracle":
            queryBuilder = new OracleQueryBuilder();
            break;
        case "mssql":
            queryBuilder = new SqlServerQueryBuilder();
            break;
        case "derby":
            queryBuilder = new DerbyQueryBuilder();
            break;
        case "postgresql":
            queryBuilder = new PostgresqlQueryBuilder();
            break;
        case "mysql":
            queryBuilder = new MysqlQueryBuilder();
            break;
        default:
            queryBuilder = new DerbyQueryBuilder();
            break;
    }
    return queryBuilder;
}
 
开发者ID:alancnet,项目名称:artifactory,代码行数:36,代码来源:DbConfigFactory.java

示例10: registerProduct

import org.springframework.beans.factory.annotation.Autowire; //导入依赖的package包/类
private void registerProduct(
		ProductLine productLineAnnotation,
		BeanDefinition runtimeBean,
		BeanDefinition productLineBean) throws NotFoundException,
		CannotCompileException, InstantiationException, IllegalAccessException, ClassNotFoundException {

	Annotation targetAnnotation = getTargetAnnotation(runtimeBean, productLineAnnotation.runtimeAnnotationClass());
	
	Class<?> productClass = productLineAnnotation.productClass();
	
	logger.info(
			"Weaving " + targetAnnotation.annotationType().getName() +
			", on Product Type " + productClass.getName() +
			", using Product Factory Line: " + productLineBean.getBeanClassName()
			);
	
	ProductFactoryLine productLine = (ProductFactoryLine) Class.forName(productLineBean.getBeanClassName()).newInstance();
	
	Class<?> annotatedProductClass = weave(
			productClass.getName(),
			runtimeBean.getBeanClassName(),
			productLine.createWeavelets(targetAnnotation)
			);

	Class<?> runtimeBeanClass = Class.forName(runtimeBean.getBeanClassName());
	
	RootBeanDefinition productBean = new RootBeanDefinition(annotatedProductClass, Autowire.BY_TYPE.value(), true);
	
	RootBeanDefinition runtimeBeanDef = new RootBeanDefinition(runtimeBeanClass, Autowire.BY_TYPE.value(), true);
	
	productLine.beforeRegistration(targetAnnotation, productBean, runtimeBeanDef);

	registry.registerBeanDefinition(annotatedProductClass.getName(), productBean);
	
	if(productLineAnnotation.registerRuntimeBean())
		registry.registerBeanDefinition(runtimeBeanClass.getName(), runtimeBeanDef);
}
 
开发者ID:mcraken,项目名称:spring-scaffy,代码行数:38,代码来源:ProductFactory.java

示例11: jsonObjectMapper

import org.springframework.beans.factory.annotation.Autowire; //导入依赖的package包/类
@Bean(name = "jsonObjectMapper", autowire = Autowire.BY_NAME)
public ObjectMapper jsonObjectMapper() {
  ObjectMapper bean = new ObjectMapper(new JsonFactory());
  bean.disableDefaultTyping();
  bean.disable(SerializationFeature.FAIL_ON_EMPTY_BEANS);
  bean.disable(SerializationFeature.WRITE_NULL_MAP_VALUES);
  bean.disable(SerializationFeature.WRITE_EMPTY_JSON_ARRAYS);

  bean.setSerializationInclusion(JsonInclude.Include.NON_NULL);
  bean.setSerializationInclusion(JsonInclude.Include.NON_EMPTY);

  //bean.registerSubtypes(LookupResult.class);
  return bean;
}
 
开发者ID:smah3sh,项目名称:mcs,代码行数:15,代码来源:MatchmakerCloudSearchConfiguration.java

示例12: databaseBackedPagingProvider

import org.springframework.beans.factory.annotation.Autowire; //导入依赖的package包/类
@Override
@Bean(autowire = Autowire.BY_TYPE)
public DatabaseBackedPagingProvider databaseBackedPagingProvider() {
	DatabaseBackedPagingProvider retVal = super.databaseBackedPagingProvider();
	retVal.setDefaultPageSize(20);
	retVal.setMaximumPageSize(500);
	return retVal;
}
 
开发者ID:jamesagnew,项目名称:hapi-fhir,代码行数:9,代码来源:TestR4Config.java

示例13: setupIndexMasterActor

import org.springframework.beans.factory.annotation.Autowire; //导入依赖的package包/类
@Bean(autowire = Autowire.BY_NAME, name = "setupIndexMasterActor")
// @Scope("prototype")
@DependsOn(value = { "actorSystem" })
public ActorRef setupIndexMasterActor()
{
    final ActorSystem system = applicationContext.getBean(ActorSystem.class);
    final SetupIndexService setupIndexService = applicationContext.getBean(SetupIndexService.class);
    final SampleDataGeneratorService sampleDataGeneratorService = applicationContext.getBean(SampleDataGeneratorService.class);
    final IndexProductDataService indexProductData = applicationContext.getBean(IndexProductDataService.class);
    return system.actorOf(Props.create(SetupIndexMasterActor.class, setupIndexService, sampleDataGeneratorService, indexProductData)
            .withDispatcher("setupIndexMasterActorDispatch"), "setupIndexMasterActor");
}
 
开发者ID:jaibeermalik,项目名称:elasticsearch-akka,代码行数:13,代码来源:AppConfiguration.java

示例14: groovyPagesTemplateEngine

import org.springframework.beans.factory.annotation.Autowire; //导入依赖的package包/类
@Bean(autowire=Autowire.BY_NAME)
@ConditionalOnMissingBean(name="groovyPagesTemplateEngine") 
GroovyPagesTemplateEngine groovyPagesTemplateEngine() {
    GroovyPagesTemplateEngine templateEngine = new GroovyPagesTemplateEngine();
    templateEngine.setReloadEnabled(gspReloadingEnabled);
    return templateEngine;
}
 
开发者ID:grails,项目名称:grails-boot,代码行数:8,代码来源:GspAutoConfiguration.java

示例15: foo

import org.springframework.beans.factory.annotation.Autowire; //导入依赖的package包/类
@Bean(autowire = Autowire.BY_TYPE)
ControllerLinkBuilderFactory foo() {
	return new ControllerLinkBuilderFactory();
}
 
开发者ID:olivergierke,项目名称:sos,代码行数:5,代码来源:RestCatalogApplication.java


注:本文中的org.springframework.beans.factory.annotation.Autowire类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。