即时通讯使用弹簧我的Java Web应用程序。该网站已经变得更大,我想设置一些配置。春天java xml配置
我一直在研究和碰到像文件生成器工厂的东西,用java config和其他替代spring xml。我不知道从哪里开始。
即时思考如何在xml(WEB/newConfig.xml)中实现配置并让它由java bean读取。基本上我想输入我的配置值到xml中,并通过java bean加载,这样我就可以在控制器和jstl中使用它。
我只是在这里举一些例子。例如XML配置:
<property name="numberOfCars" value="3" />
<property name="webSiteName" value="New Spring Web App" />
....
和我在java类阅读:
class Config {
public getNumberOfCars() {
return numOfCars;
}
public getWebSiteName() {
return webSiteName;
}
}
我应该在哪里开始,我可以读到网上资料?
==============================
更新
这里是我创建的。
applicationContext.xml
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:aop="http://www.springframework.org/schema/aop" xmlns:context="http://www.springframework.org/schema/context"
xmlns:jee="http://www.springframework.org/schema/jee" xmlns:tx="http://www.springframework.org/schema/tx"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-3.0.xsd http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.0.xsd http://www.springframework.org/schema/jee http://www.springframework.org/schema/jee/spring-jee-3.0.xsd http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-3.0.xsd">
<context:property-placeholder location="/WEB-INF/your_prop_file.properties" />
<bean id="ConfigMgr" class="org.domain.class.ConfigMgr">
<property name="username" value="${username}">
</bean>
</beans>
you_prop_file.properties
username=hello world name
ConfigMgr.java
public class ConfigMgr {
private String username;
...getter
...setter
}
在我的控制器
,这里是我做了什么:
ConfigMgr config = new ConfigMgr();
sysout.out.println(config.getUsername());
我得到空和我我肯定在这里错过了一些东西。我应该在哪里设置用户名值到ConfigMgr类?
阅读[spring documentation](http://docs.spring.io/spring/docs/3.2.4.RELEASE/spring-framework-reference/html/)...它有超过所需的信息 –
要求对于非现场资源而言,关于stackoverflow的话题已经不再。但是,您需要启动的地方是第5章Spring 3.2.4文档的IoC容器。 –
确定tks man ..将查看文档。我似乎违反了这些天的计算器= | – nuttynibbles