use of org.springframework.beans.factory.xml.XmlBeanFactory in project tutorials by eugenp.
the class BeanFactoryWithClassPathResourceIntegrationTest method createBeanFactoryAndCheckEmployeeBean.
@Test
public void createBeanFactoryAndCheckEmployeeBean() {
Resource res = new ClassPathResource("beanfactory-example.xml");
BeanFactory factory = new XmlBeanFactory(res);
Employee emp = (Employee) factory.getBean("employee");
assertTrue(factory.isSingleton("employee"));
assertTrue(factory.getBean("employee") instanceof Employee);
assertTrue(factory.isTypeMatch("employee", Employee.class));
assertTrue(factory.getAliases("employee").length > 0);
}
use of org.springframework.beans.factory.xml.XmlBeanFactory in project lzl_workspace by hpulzl.
the class test method xmlBeanFactory.
public static void xmlBeanFactory() {
// 加载配置文件
ClassPathResource resource = new ClassPathResource("ApplicationContext.xml");
// 解析文件
BeanFactory beanFactory = new XmlBeanFactory(resource);
// 创建对应bean,依赖注入过程
Person p = (Person) beanFactory.getBean("person");
System.out.println("p = " + p);
}
use of org.springframework.beans.factory.xml.XmlBeanFactory in project twitter4j by yusuke.
the class SpringCompatibilityTest method setUp.
@BeforeEach
protected void setUp() throws Exception {
writeFile("./twitter4j.properties", "user=one" + "\n" + "password=pasword-one");
Resource res = new ClassPathResource("spring-beans.xml");
beanFactory = new XmlBeanFactory(res);
}
use of org.springframework.beans.factory.xml.XmlBeanFactory in project ignite by apache.
the class GarHelloWorldTask method split.
/**
* {@inheritDoc}
*/
@Override
public Collection<? extends ComputeJob> split(int gridSize, String arg) throws IgniteException {
// Create Spring context.
AbstractBeanFactory fac = new XmlBeanFactory(new ClassPathResource("org/apache/ignite/spi/deployment/uri/tasks/gar-spring-bean.xml", getClass().getClassLoader()));
fac.setBeanClassLoader(getClass().getClassLoader());
// Load imported bean from GAR/lib folder.
GarHelloWorldBean bean = (GarHelloWorldBean) fac.getBean("example.bean");
String msg = bean.getMessage(arg);
assert msg != null;
// Split the passed in phrase into multiple words separated by spaces.
List<String> words = Arrays.asList(msg.split(" "));
Collection<ComputeJob> jobs = new ArrayList<>(words.size());
// Use imperative OOP APIs.
for (String word : words) {
// Every job gets its own word as an argument.
jobs.add(new ComputeJobAdapter(word) {
/*
* Simply prints the job's argument.
*/
@Nullable
@Override
public Serializable execute() {
System.out.println(">>>");
System.out.println(">>> Printing '" + argument(0) + "' on this node from grid job.");
System.out.println(">>>");
// This job does not return any result.
return null;
}
});
}
return jobs;
}
use of org.springframework.beans.factory.xml.XmlBeanFactory in project ignite by apache.
the class GridUriDeploymentSpringParser method parseTasksDocument.
/**
* Converts given input stream expecting XML inside to
* {@link GridUriDeploymentSpringDocument}.
* <p>
* This is a workaround for the {@link InputStreamResource} which does
* not work properly.
*
* @param in Input stream with XML.
* @param log Logger
* @return Grid wrapper for the input stream.
* @throws org.apache.ignite.spi.IgniteSpiException Thrown if incoming input stream could not be
* read or parsed by {@code Spring} {@link XmlBeanFactory}.
* @see XmlBeanFactory
*/
static GridUriDeploymentSpringDocument parseTasksDocument(InputStream in, IgniteLogger log) throws IgniteSpiException {
assert in != null;
// Note: use ByteArrayResource instead of InputStreamResource because InputStreamResource doesn't work.
ByteArrayOutputStream out = new ByteArrayOutputStream();
try {
U.copy(in, out);
XmlBeanFactory factory = new XmlBeanFactory(new ByteArrayResource(out.toByteArray()));
return new GridUriDeploymentSpringDocument(factory);
} catch (BeansException | IOException e) {
throw new IgniteSpiException("Failed to parse spring XML file.", e);
} finally {
U.close(out, log);
}
}
Aggregations