如何用Spring 3.1的profile environmentt和Profile简化工作

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

我要回帖

更多关于 spring environment类 的文章

更多推荐

版权声明:文章内容来源于网络,版权归原作者所有,如有侵权请点击这里与我们联系,我们将及时删除。

点击添加站长微信