我们有4个应用程序运行在一个Tomcat7服务器上。现有的应用程序工作在Hibernate和Spring上。后端连接到第二个数据库,一些旧模式在这里实时保存。每个模式都被称为xxx_live和xxx_test。
当Tomcat服务器启动时,将为正确的环境设置一个JNDI属性。
在PropertySourcesPlaceholderConfigurer类的扩展上解析了这些属性:
public class GenericPropertySourcesPlaceholderConfigurer extends PropertySourcesPlaceholderConfigurer {
private String application;
private String environment;
private static final String ENVIRONMENT = "environment";
public GenericPropertySourcesPlaceholderConfigurer(String application) throws IOException {
this.application = application;
this.environment = System.getProperty(ENVIRONMENT);
if (this.environment == null) {
this.environment = System.getenv().get(ENVIRONMENT);
}
initPropertySources();
}
/**
* setup default properties configuration
* Default configuration properties look like :
* app-global.properties
* app-environment.properties
* jndi properties
*/
private void initPropertySources() throws IOException {
MutablePropertySources propertySources = new MutablePropertySources();
propertySources.addLast(new ResourcePropertySource(new ClassPathResource(MessageFormat.format("properties/{0}-global.properties", application))));
propertySources.addLast(new ResourcePropertySource(new ClassPathResource(MessageFormat.format("properties/{0}/{1}.properties", environment, application))));
propertySources.addLast(new NotFailingJndiPropertySource("jndi"));
setPropertySources(propertySources);
setIgnoreResourceNotFound(false);
setIgnoreUnresolvablePlaceholders(true);
}
}现在,我们正在将所有内容迁移到MyBatis。是否有方法将这些属性注入或解析到我的XML配置中?类似于:
<select id="findAllUsers" parameterType="list" resultType="user">
SELECT * FROM ${mybatis.default_schema}.USER
</select>发布于 2013-02-11 15:09:41
是的,你绝对可以通过这个房产。
DAO层中的函数声明(JAVA Mapper for mybatis在春季)类似于
List<User> findAllUsers(@Param("schemaName") String schemaName)调用此函数时,将模式名称作为参数传递。
很少有建议(假设您是MyBatis新手)
<util:properties id="mailProps" location="classpath:mail.properties" />com.foo.bar是您的Java表示您的XML的包所在的位置。
这样,您将实际使用spring的好处,即DI / IOCparameterType将是String或java.lang.String,而不是list。如果你需要进一步的帮助/任何疑问,可以随时要求回复。
谢谢。
https://stackoverflow.com/questions/14814560
复制相似问题