reading Repository from xml config
Hi all,
I'm kinda new to spring and have a problem, that I wanna do in a quot;cleanquot; way, that's why I ask here (I just found some hacks for that problem).
I'm developing a CMIS client that can interact with various different repositorys and just need to pass it a connection string (like database).
I created this xml config inside my WEB-INF folder called repository-context.xml:Code:
lt;?xml version=quot;1.0quot; encoding=quot;UTF-8quot;?gt;
lt;beans xmlns=quot;schema/beansquot;
xmlns:xsi=quot;2001/XMLSchema-instancequot;
xsi:schemaLocation=quot;schema/beans schema/beans/spring-beans.xsdquot;gt;
lt;bean id=quot;repositoryquot; destroy-method=quot;closequot; class=quot;???quot;gt;
lt;property name=quot;hostquot; value=quot;localhostquot; /gt;
lt;property name=quot;portquot; value=quot;8081quot; /gt;
lt;property name=quot;usernamequot; value=quot;adminquot; /gt;
lt;property name=quot;passwordquot; value=quot;adminquot; /gt;
lt;/beangt;
lt;bean id=quot;FileUploaderquot; class=quot;com.tie.bl.docrepobrowser.FileUploaderquot;gt;
lt;property name=quot;repositoryquot; ref=quot;repositoryquot; /gt;
lt;/beangt;
lt;bean id=quot;ManageDocsquot; class=quot;com.tie.bl.docrepobrowser.ManageDocsquot;gt;
lt;property name=quot;repositoryquot; ref=quot;repositoryquot; /gt;
lt;/beangt;
lt;/beansgt;
Here my first problem is, what class is the bean?
And my 2nd Problem is, what is the smoothest way to get the properties (host,port,...) inside my FileUploader.java and inside my ManageDocs.java
thanks for your help.
Hello
Here my first problem is, what class is the bean?
I suggest you work with a .properties file to get the the data for host,port,... etc
Seems you want a generic class about a dataSource configuration? If yes
the class Could be a DataSource implementation, for example a BasicDataSource, BTW I used to work with C3PO
Here 12.2.1.2 JdbcTemplate best practices has some examples
And my 2nd Problem is, what is the smoothest way to get the properties (host,port,...) inside my FileUploader.java and inside my ManageDocs.java
I suggest you read the Spring Reference documentation
ok what I did so far:
a class for my object:Code:
package com.tie.bl.modules.docrepbrowser;
public class TieRepository {
private String host;
private String port;
private String username;
private String password;
public TieRepository() {}
public TieRepository(String host, String port, String username, String password){
this.host = host;
this.port = port;
this.username = username;
this.password = password;
}
public void setHost(String host)
{
this.host = host;
}
....... various setter and getter for the props
public String getHost()
{
return host;
}
}
my repository-context.xml:Code:
lt;?xml version=quot;1.0quot; encoding=quot;UTF-8quot;?gt;
lt;!DOCTYPE beans PUBLIC quot;-//SPRING//DTD BEAN//ENquot; quot;dtd/spring-beans.dtdquot;gt;
lt;beansgt;
lt;bean id=quot;repositorybeanquot; class=quot;com.tie.bl.modules.docrepbrowser.TieRepositoryquot;gt;
lt;property name=quot;hostquot; value=quot;172.16.5.131quot; /gt;
lt;property name=quot;portquot; value=quot;8081quot; /gt;
lt;property name=quot;usernamequot; value=quot;adminquot; /gt;
lt;property name=quot;passwordquot; value=quot;adminquot; /gt;
lt;/beangt;
lt;/beansgt;
and my code to retrieve it:Code:
ApplicationContext context = new FileSystemXmlApplicationContext(quot;classpath*:/WEB-INF/applicationContext-repository.xmlquot;);
TieRepository repo = (TieRepository)context.getBean(quot;repositorybeanquot;);
my problem:
I get a:
NoSuchBeanDefinitionException: No bean named 'repositorybean' is defined
exception. Can anybody give me a hint on that? |