本文整理汇总了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
}
}
示例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
}
}
示例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");
}
示例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;
}
示例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;
}
示例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;
}
示例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));
}
}
示例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;
}
示例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;
}
示例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);
}
示例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;
}
示例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;
}
示例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");
}
示例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;
}
示例15: foo
import org.springframework.beans.factory.annotation.Autowire; //导入依赖的package包/类
@Bean(autowire = Autowire.BY_TYPE)
ControllerLinkBuilderFactory foo() {
return new ControllerLinkBuilderFactory();
}