本文整理汇总了Java中org.springframework.beans.MutablePropertyValues.addPropertyValue方法的典型用法代码示例。如果您正苦于以下问题:Java MutablePropertyValues.addPropertyValue方法的具体用法?Java MutablePropertyValues.addPropertyValue怎么用?Java MutablePropertyValues.addPropertyValue使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.springframework.beans.MutablePropertyValues
的用法示例。
在下文中一共展示了MutablePropertyValues.addPropertyValue方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getValues
import org.springframework.beans.MutablePropertyValues; //导入方法依赖的package包/类
/**
* Same as getValues(), but property keys are prefixed with the specified prefix.
*
* @param propertyKeyPrefix
*
*/
public PropertyValues getValues(String propertyKeyPrefix) {
if (propertyKeyPrefix == null) {
propertyKeyPrefix = "";
} else {
propertyKeyPrefix += ".";
}
MutablePropertyValues props = new MutablePropertyValues();
for (String propertyName : getParameterNames()) {
String strVal = getParameterStringValue(propertyName);
if (strVal != null) {
props.addPropertyValue(propertyKeyPrefix + propertyName, strVal);
}
}
return props;
}
示例2: getPropertyValuesForNamePrefix
import org.springframework.beans.MutablePropertyValues; //导入方法依赖的package包/类
private MutablePropertyValues getPropertyValuesForNamePrefix(
MutablePropertyValues propertyValues) {
if (!StringUtils.hasText(this.namePrefix) && !this.ignoreNestedProperties) {
return propertyValues;
}
MutablePropertyValues rtn = new MutablePropertyValues();
for (PropertyValue value : propertyValues.getPropertyValues()) {
String name = value.getName();
for (String prefix : new RelaxedNames(stripLastDot(this.namePrefix))) {
for (String separator : new String[] { ".", "_" }) {
String candidate = (StringUtils.hasLength(prefix) ? prefix + separator
: prefix);
if (name.startsWith(candidate)) {
name = name.substring(candidate.length());
if (!(this.ignoreNestedProperties && name.contains("."))) {
PropertyOrigin propertyOrigin = OriginCapablePropertyValue
.getOrigin(value);
rtn.addPropertyValue(new OriginCapablePropertyValue(name,
value.getValue(), propertyOrigin));
}
}
}
}
}
return rtn;
}
示例3: addBindValues
import org.springframework.beans.MutablePropertyValues; //导入方法依赖的package包/类
/**
* Merge URI variables into the property values to use for data binding.
*/
@Override
@SuppressWarnings("unchecked")
protected void addBindValues(MutablePropertyValues mpvs, ServletRequest request) {
String attr = HandlerMapping.URI_TEMPLATE_VARIABLES_ATTRIBUTE;
Map<String, String> uriVars = (Map<String, String>) request.getAttribute(attr);
if (uriVars != null) {
for (Entry<String, String> entry : uriVars.entrySet()) {
if (mpvs.contains(entry.getKey())) {
logger.warn("Skipping URI variable '" + entry.getKey()
+ "' since the request contains a bind value with the same name.");
}
else {
mpvs.addPropertyValue(entry.getKey(), entry.getValue());
}
}
}
}
示例4: testBeanNameViewResolver
import org.springframework.beans.MutablePropertyValues; //导入方法依赖的package包/类
@Test
public void testBeanNameViewResolver() throws ServletException {
StaticWebApplicationContext wac = new StaticWebApplicationContext();
wac.setServletContext(new MockServletContext());
MutablePropertyValues pvs1 = new MutablePropertyValues();
pvs1.addPropertyValue(new PropertyValue("url", "/example1.jsp"));
wac.registerSingleton("example1", InternalResourceView.class, pvs1);
MutablePropertyValues pvs2 = new MutablePropertyValues();
pvs2.addPropertyValue(new PropertyValue("url", "/example2.jsp"));
wac.registerSingleton("example2", JstlView.class, pvs2);
BeanNameViewResolver vr = new BeanNameViewResolver();
vr.setApplicationContext(wac);
wac.refresh();
View view = vr.resolveViewName("example1", Locale.getDefault());
assertEquals("Correct view class", InternalResourceView.class, view.getClass());
assertEquals("Correct URL", "/example1.jsp", ((InternalResourceView) view).getUrl());
view = vr.resolveViewName("example2", Locale.getDefault());
assertEquals("Correct view class", JstlView.class, view.getClass());
assertEquals("Correct URL", "/example2.jsp", ((JstlView) view).getUrl());
}
示例5: testComplexObject
import org.springframework.beans.MutablePropertyValues; //导入方法依赖的package包/类
@Test
public void testComplexObject() {
TestBean tb = new TestBean();
String newName = "Rod";
String tbString = "Kerry_34";
BeanWrapper bw = new BeanWrapperImpl(tb);
bw.registerCustomEditor(ITestBean.class, new TestBeanEditor());
MutablePropertyValues pvs = new MutablePropertyValues();
pvs.addPropertyValue(new PropertyValue("age", new Integer(55)));
pvs.addPropertyValue(new PropertyValue("name", newName));
pvs.addPropertyValue(new PropertyValue("touchy", "valid"));
pvs.addPropertyValue(new PropertyValue("spouse", tbString));
bw.setPropertyValues(pvs);
assertTrue("spouse is non-null", tb.getSpouse() != null);
assertTrue("spouse name is Kerry and age is 34",
tb.getSpouse().getName().equals("Kerry") && tb.getSpouse().getAge() == 34);
}
示例6: testAutowireWithUnsatisfiedConstructorDependency
import org.springframework.beans.MutablePropertyValues; //导入方法依赖的package包/类
@Test
public void testAutowireWithUnsatisfiedConstructorDependency() {
DefaultListableBeanFactory lbf = new DefaultListableBeanFactory();
MutablePropertyValues pvs = new MutablePropertyValues();
pvs.addPropertyValue(new PropertyValue("name", "Rod"));
RootBeanDefinition bd = new RootBeanDefinition(TestBean.class);
bd.setPropertyValues(pvs);
lbf.registerBeanDefinition("rod", bd);
assertEquals(1, lbf.getBeanDefinitionCount());
try {
lbf.autowire(UnsatisfiedConstructorDependency.class, AutowireCapableBeanFactory.AUTOWIRE_CONSTRUCTOR, true);
fail("Should have unsatisfied constructor dependency on SideEffectBean");
}
catch (UnsatisfiedDependencyException ex) {
// expected
}
}
示例7: testExtensiveCircularReference
import org.springframework.beans.MutablePropertyValues; //导入方法依赖的package包/类
@Test
public void testExtensiveCircularReference() {
DefaultListableBeanFactory lbf = new DefaultListableBeanFactory();
for (int i = 0; i < 1000; i++) {
MutablePropertyValues pvs = new MutablePropertyValues();
pvs.addPropertyValue(new PropertyValue("spouse", new RuntimeBeanReference("bean" + (i < 99 ? i + 1 : 0))));
RootBeanDefinition bd = new RootBeanDefinition(TestBean.class);
bd.setPropertyValues(pvs);
lbf.registerBeanDefinition("bean" + i, bd);
}
lbf.preInstantiateSingletons();
for (int i = 0; i < 1000; i++) {
TestBean bean = (TestBean) lbf.getBean("bean" + i);
TestBean otherBean = (TestBean) lbf.getBean("bean" + (i < 99 ? i + 1 : 0));
assertTrue(bean.getSpouse() == otherBean);
}
}
示例8: registerBeanDefinitions
import org.springframework.beans.MutablePropertyValues; //导入方法依赖的package包/类
@Override
public void registerBeanDefinitions(AnnotationMetadata importingClassMetadata, BeanDefinitionRegistry registry) {
Map<Object, Object> targetDataSources = new HashMap<Object, Object>();
// 将主数据源添加到更多数据源中
targetDataSources.put("dataSource", defaultDataSource);
DynamicDataSourceContextHolder.dataSourceIds.add("dataSource");
// 添加更多数据源
targetDataSources.putAll(customDataSources);
for (String key : customDataSources.keySet()) {
DynamicDataSourceContextHolder.dataSourceIds.add(key);
}
// 创建DynamicDataSource
GenericBeanDefinition beanDefinition = new GenericBeanDefinition();
beanDefinition.setBeanClass(DynamicDataSource.class);
beanDefinition.setSynthetic(true);
MutablePropertyValues mpv = beanDefinition.getPropertyValues();
mpv.addPropertyValue("defaultTargetDataSource", defaultDataSource);
mpv.addPropertyValue("targetDataSources", targetDataSources);
registry.registerBeanDefinition("dataSource", beanDefinition);
logger.info("Dynamic DataSource Registry");
}
示例9: initializeForProvider
import org.springframework.beans.MutablePropertyValues; //导入方法依赖的package包/类
public void initializeForProvider(ConfigurableListableBeanFactory beanFactory, String application, String refBeanName)
throws BeansException {
BeanDefinitionRegistry registry = (BeanDefinitionRegistry) beanFactory;
// <dubbo:service interface="org.bytesoft.bytejta.supports.wire.RemoteCoordinator" group="org-bytesoft-bytetcc"
// ref="dispatcherCoordinator" filter="compensable" loadbalance="compensable" cluster="failfast" />
GenericBeanDefinition beanDef = new GenericBeanDefinition();
beanDef.setBeanClass(com.alibaba.dubbo.config.spring.ServiceBean.class);
MutablePropertyValues mpv = beanDef.getPropertyValues();
mpv.addPropertyValue("interface", RemoteCoordinator.class.getName());
mpv.addPropertyValue("ref", new RuntimeBeanReference(refBeanName));
mpv.addPropertyValue("cluster", "failfast");
mpv.addPropertyValue("loadbalance", "compensable");
mpv.addPropertyValue("filter", "compensable");
mpv.addPropertyValue("group", "org-bytesoft-bytetcc");
mpv.addPropertyValue("retries", "0");
mpv.addPropertyValue("timeout", "6000");
String skeletonBeanId = String.format("[email protected]%s", RemoteCoordinator.class.getName());
registry.registerBeanDefinition(skeletonBeanId, beanDef);
}
示例10: parse
import org.springframework.beans.MutablePropertyValues; //导入方法依赖的package包/类
@Override
public BeanDefinition parse(Element element, ParserContext parserContext) {
FieldDefine fieldDefine = parseFieldDefine(element);
String id = fieldDefine.getId();
if (StringUtils.isEmpty(id)) {
id = fieldDefine.toString()+"-"+System.currentTimeMillis();
}
RootBeanDefinition beanDefinition = new RootBeanDefinition();
beanDefinition.setBeanClass(FieldDefine.class);
beanDefinition.setLazyInit(false);
BeanDefinitionRegistry registry = parserContext.getRegistry();
if (registry.containsBeanDefinition(id)) {
throw new IllegalStateException("Duplicate spring bean id " + id);
}
registry.registerBeanDefinition(id, beanDefinition);
MutablePropertyValues propertyValues = beanDefinition.getPropertyValues();
propertyValues.addPropertyValue("id", id);
propertyValues.addPropertyValue("name", fieldDefine.getName());
propertyValues.addPropertyValue("type", fieldDefine.getType());
propertyValues.addPropertyValue("selector", fieldDefine.getSelector());
propertyValues.addPropertyValue("processor", fieldDefine.getProcessor());
propertyValues.addPropertyValue("defines", fieldDefine.getDefines());
return beanDefinition;
}
示例11: registryMangoDao
import org.springframework.beans.MutablePropertyValues; //导入方法依赖的package包/类
/**
* 向spring中注入dao代理
* @param beanFactory
*/
private void registryMangoDao(DefaultListableBeanFactory beanFactory){
for (Class<?> daoClass : findMangoDaoClasses(config.getScanPackage())) {
GenericBeanDefinition bf = new GenericBeanDefinition();
bf.setBeanClassName(daoClass.getName());
MutablePropertyValues pvs = bf.getPropertyValues();
pvs.addPropertyValue("daoClass", daoClass);
bf.setBeanClass(factoryBeanClass);
bf.setPropertyValues(pvs);
bf.setLazyInit(false);
beanFactory.registerBeanDefinition(daoClass.getName(), bf);
}
}
示例12: postProcessPropertyValues
import org.springframework.beans.MutablePropertyValues; //导入方法依赖的package包/类
public PropertyValues postProcessPropertyValues(PropertyValues pvs, PropertyDescriptor[] pds, Object bean,
String beanName) throws BeansException {
MutablePropertyValues newprops = new MutablePropertyValues(pvs);
for (PropertyDescriptor pd : pds) {
ServiceReference s = hasServiceProperty(pd);
if (s != null && !pvs.contains(pd.getName())) {
try {
if (logger.isDebugEnabled())
logger.debug("Processing annotation [" + s + "] for [" + beanName + "." + pd.getName() + "]");
FactoryBean importer = getServiceImporter(s, pd.getWriteMethod(), beanName);
// BPPs are created in stageOne(), even though they are run in stageTwo(). This check means that
// the call to getObject() will not fail with ServiceUnavailable. This is safe to do because
// ServiceReferenceDependencyBeanFactoryPostProcessor will ensure that mandatory services are
// satisfied before stageTwo() is run.
if (bean instanceof BeanPostProcessor) {
ImporterCallAdapter.setCardinality(importer, Availability.OPTIONAL);
}
newprops.addPropertyValue(pd.getName(), importer.getObject());
}
catch (Exception e) {
throw new FatalBeanException("Could not create service reference", e);
}
}
}
return newprops;
}
示例13: createBeanReferenceDefinition
import org.springframework.beans.MutablePropertyValues; //导入方法依赖的package包/类
private AbstractBeanDefinition createBeanReferenceDefinition(String beanName, BeanDefinition actualDef) {
GenericBeanDefinition def = new GenericBeanDefinition();
def.setBeanClass(BeanReferenceFactoryBean.class);
def.setAttribute(GENERATED_REF, Boolean.TRUE);
def.setOriginatingBeanDefinition(actualDef);
def.setDependsOn(new String[] { beanName });
def.setSynthetic(true);
MutablePropertyValues mpv = new MutablePropertyValues();
mpv.addPropertyValue(TARGET_BEAN_NAME_PROP, beanName);
def.setPropertyValues(mpv);
return def;
}
示例14: registerBeanDefinitions
import org.springframework.beans.MutablePropertyValues; //导入方法依赖的package包/类
@Override
public void registerBeanDefinitions(AnnotationMetadata importingClassMetadata, BeanDefinitionRegistry registry) {
if (LOGGER.isDebugEnabled()) {
LOGGER.debug("动态数据源注册开始>>>");
}
// 添加主数据源
targetDataSources.put("master", DynamicDataSourceHolder.getMasterDS());
if (LOGGER.isDebugEnabled()) {
LOGGER.debug("提供可选取Master数据源:{}", "master");
}
// 添加从数据源
targetDataSources.putAll(DynamicDataSourceHolder.getSlaveDSMap());
if (LOGGER.isDebugEnabled()) {
LOGGER.debug("提供可选取Slave数据源:{}", DynamicDataSourceHolder.getSlaveDSMap().keySet());
}
for (String key : DynamicDataSourceHolder.getSlaveDSMap().keySet()) {
DynamicDataSourceHolder.getSlaveDSKeys().add(key);
}
// 创建DynamicDataSource
GenericBeanDefinition beanDefinition = new GenericBeanDefinition();
beanDefinition.setBeanClass(DynamicDataSource.class);
beanDefinition.setSynthetic(true);
MutablePropertyValues mpv = beanDefinition.getPropertyValues();
mpv.addPropertyValue("defaultTargetDataSource", DynamicDataSourceHolder.getMasterDS());
mpv.addPropertyValue("targetDataSources", targetDataSources);
registry.registerBeanDefinition("dataSource", beanDefinition);
if (LOGGER.isDebugEnabled()) {
LOGGER.debug("<<<动态数据源注册结束");
}
}
示例15: registerDynamicDataSourceBeanDefinition
import org.springframework.beans.MutablePropertyValues; //导入方法依赖的package包/类
/**
* @Title: registerDynamicDataSourceBeanDefinition
* @Description: 注册动态数据源
* @author Kola 6089555
* @date 2017年4月26日 下午1:26:55
* @param registry
*/
private void registerDynamicDataSourceBeanDefinition(BeanDefinitionRegistry registry) {
GenericBeanDefinition beanDefinition = new GenericBeanDefinition();
beanDefinition.setBeanClass(DynamicDataSource.class);
beanDefinition.setSynthetic(true);
beanDefinition.setPrimary(true);
MutablePropertyValues mpv = beanDefinition.getPropertyValues();
mpv.addPropertyValue("defaultTargetDataSource", defaultDataSource);
mpv.addPropertyValue("targetDataSources", targetDataSources);
registry.registerBeanDefinition("dataSource", beanDefinition);
LOGGER.info("Dynamic DataSource Registry");
}
开发者ID:6089555,项目名称:spring-boot-starter-dynamic-datasource,代码行数:19,代码来源:DynamicDataSourceRegister.java