& 开源中国(OSChina.NET) |
开源中国社区(OSChina.net)是工信部
指定的官方社区如何用Spring 3.1的Environment和Profile简化工作_百度知道
如何用Spring 3.1的Environment和Profile简化工作
提问者采纳
1为这个问题提供了一个解决方案(如果你还没有为自己的项目升级Spring版本。 ClassPathXmlApplicationContext.,嗯。 Spring在容器中引入Environment和Profile的概念,你麻烦大了)。每个应用程序上下文都有一个都可以访Environment对象.Spring 3
来自团队:
其他类似问题
为您推荐:
profile的相关知识
等待您来回答
下载知道APP
随时随地咨询
出门在外也不愁如何用Spring 3.1的Environment和Profile简化工作_百度知道
如何用Spring 3.1的Environment和Profile简化工作
提问者采纳
Java企业级容器(包括JBoss。转载、Glassfish等) 独立运行的Java应用程序 GUI应用程序 测试框架 如果我的回答没能帮助您这些部署配置大致可以分为以下几类、Tomcat,请继续追问,仅供参考、WebLogic
为您推荐:
等待您来回答
下载知道APP
随时随地咨询
出门在外也不愁如何用Spring 3.1的Environment和Profile简化工作_百度知道
如何用Spring 3.1的Environment和Profile简化工作
/servlet&&.getEnvironment();/;/&/。下面看一个例子;org?&/,在初始化容器的准备工作完成后; ctx.0"./&beans xmlns=".setActiveProfiles("。假设下面是我的应用程序中,数据源实例的定义.setActiveProfiles(&servlet-class&init-param&bean id=&UTF-8& org./UTF-8".dbcp: &property name="。 在Spring 3;sa"。 ClassPathXmlApplicationContext classPathXmlApplicationContext = new ClassPathXmlApplicationContext();url&>,&; class=":jndi-lookup id=&*C/ 这样。 &…". & ConfigurableEnvironment configurableEnvironment = classPathXmlApplicationClocalhost& &War的初始化参数传入; <.getEnvironment();close&beans profile="。这里,嗯.1为这个问题提供了一个解决方案(如果你还没有为自己的项目升级Spring版本; & >.DispatcherServlet &servlet-name& & value=&property name=& &beans&>。 GenericXmlApplicationContext类的特点是可以通过Setter方法完成所有的配置;bean& <:dataSource& destroy-method=&;1;property name=&property name=& value="。Profile是Bean的属性: &beans/:mydatasource&&beans xmlns="?& &), &standalone&bean>.property name=& &);/,修改配置上下文为,增加了一个新的容器类GenericXmlApplicationC)?&&password&& value=".BasicDataSource&driverClassName& <: GenericXmlApplicationContext ctx = new GenericXmlApplicationContext(); value=&/ &username& encoding=".jdbcDriver&& 此外; <,你所创建的Bean在载入容器中后是没有Profile对象的,我将活动Profile设置为“standalone”;/ &beans xmlns=",这会导致产生多个文件; profile=&container&;sa":/ <.0&standalone".refresh();/。对于不同运行环境问题来说; & value=&dataSource&org.xml"。在这个工程里;servlet-name&property name=".1中;/beans& &>,可以作为ClassPathXmlApplicationContext和FileSystemXmlApplicationContext之外的另一个选择; <.jdbcDriver&…&&url&¶m-name& 另一种切换Profile的方法是在运行时作为系统参数传入?xml version=&bean id=&/ & & value=& <,实际上并不会对当前的配置上下文产生影响;/password& &dataSource&beans&property name=&driverClassName& destroy-method="。 下面的代码展示了如何使用GenericXmlApplicationContext类初始化容器;password&close",也可以作为Ear/java.setActiveProfiles(&init-param&&>:/,我的解决方案是使用使用多个Profile来适应不同运行时,我希望代码既可以作为“standalone”运行在应用程序容器之外.commons: &…"://,才会实例化这个Bean.BasicDataSource&/。这个解决方案的优势是你可以自行决定如何使用Pbeans/。 Spring在容器中引入Environment和Profile的概念; &/: ctx?xml version=".active& 在Spring 3.hsqldb. <,还可以作为“container”运行在容器中: -Dproduction& jndi-name=&standalone&bean id=&&/:sa&&/ value="?xml version=&/>: value=",需要调用refresh()方法完成实际的初始化工作;/>: & value=",就可以通过下面的代码快速切换P& & encoding=&/:beans& 只有当活动Profile设置为“standalone”时;&property name=",我们重新编写一下数据源配置文件,因为还没有配置Profile实例,你麻烦大了);standalone& 虽然做了上面的配置; &&//。记住;/property name=&username"。 默认星空情况下; &UTF-8&property name=&property name=& class=".getEnvironment()。在较早的Spring版本中,而无需依靠笨重的构造器去完成配置;1;property name=&标签内;/,你无法配置单独的Bean来选择PdataSource".beans&standalone& value="。现在;标签可以嵌套在&activemq& &/.load(&>。每个应用程序上下文都有一个都可以访Environment对象,而Ant的通配符无法在运行时找到正确的配置文件;servlet-class&driverClassName¶m-value&username",例如; <。所以;dispatcher<,而不是一个实例对象.active="。 1 &servlet& encoding=&localhost& &bean&localhost&);>,我可以设置多个Purl".0& & value=".jdbcDriver&& <,下面的代码设置了Profile为“standalone”与“activemq”。大多数讲解Spring Profile的例子都是在开发模式或生产模式下;;container".getEnvironment();1; 这里;param-name& 每种运行环境都有很多活动Profile类可供使用;/param-value& <:hsqldb,因此.beans profile=".hsqldb. < Spring 3;spring.& &/ value=".0中
其他类似问题
为您推荐:
等待您来回答
下载知道APP
随时随地咨询
出门在外也不愁}