私のJava Webアプリに春を使用しています。サイトが大きくなったので、いくつかの構成を設定したいと思います。
私は調査を行っており、ドキュメント ビルダー ファクトリ、Spring xml を Java 構成などに置き換えることなどに出くわしました。どこから始めたらいいのかわからない。
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());
私はnullになっており、ここに何かが欠けていると確信しています。ユーザー名の値を ConfigMgr クラスのどこに設定すればよいですか?