当前位置: 首页 > news >正文

网站开发提供图片加载速度wordpress速度

网站开发提供图片加载速度,wordpress速度,电子商务目前就业形势,深圳域名服务器地址我的上一个博客介绍了Spring 3.1的配置文件#xff0c;并解释了使用它们的业务案例#xff0c;并演示了它们在Spring XML配置文件中的用法。 但是#xff0c;似乎很多开发人员更喜欢使用Spring的基于Java的应用程序配置#xff0c;因此Spring设计了一种使用带有现有Configu… 我的上一个博客介绍了Spring 3.1的配置文件并解释了使用它们的业务案例并演示了它们在Spring XML配置文件中的用法。 但是似乎很多开发人员更喜欢使用Spring的基于Java的应用程序配置因此Spring设计了一种使用带有现有Configuration批注的配置文件的方法。 我将使用我以前的博客中的Person类来演示配置文件和Configuration批注。 这是一个简单的bean类其属性取决于激活的概要文件而有所不同。 public class Person { private final String firstName; private final String lastName; private final int age; public Person(String firstName, String lastName, int age) { this.firstName firstName; this.lastName lastName; this.age age; } public String getFirstName() { return firstName; } public String getLastName() { return lastName; } public int getAge() { return age; } } 请记住Spring专家建议仅在需要加载不同类型或类集的情况下使用Spring配置文件并且在设置属性时应继续使用PropertyPlaceholderConfigurer 。 我违反规则的原因是我想尝试编写最简单的代码来演示配置文件和Java配置。 使用Spring配置文件和Java配置的核心是Spring的新Profile注释。 Profile批注用于将配置文件名称附加到Configuration批注。 它采用一个可以以两种方式使用的参数。 首先将单个配置文件附加到Configuration批注 Profile(test1) 其次附加多个配置文件 Profile({ test1, test2 }) 同样我将定义两个配置文件“ test1”和“ test2”并将每个配置文件与一个配置文件相关联。 首先是“ test1” Configuration Profile(test1) public class Test1ProfileConfig { Bean public Person employee() { return new Person(John, Smith, 55); } } …然后是“ test2” Configuration Profile(test2) public class Test2ProfileConfig { Bean public Person employee() { return new Person(Fred, Williams, 22); } } 在上面的代码中您可以看到我正在创建一个Person Bean其有效的雇员 ID来自方法名在每个概要文件中返回不同的属性值。 另请注意 Profile被标记为 Target(valueTYPE) …这意味着只能将其放在Configuration批注旁边。 将Profile附加到Configuration后 下一步是激活您选择的Profile 。 这使用了与我在上一个博客中描述的原理和技术完全相同的方法并且在我看来最有用的激活技术是使用“ spring.profiles.active”系统属性。 Test public void testProfileActiveUsingSystemProperties() { System.setProperty(spring.profiles.active, test1); ApplicationContext ctx new ClassPathXmlApplicationContext(profiles-config.xml); Person person ctx.getBean(employee, Person.class); String firstName person.getFirstName(); assertEquals(John, firstName); } 显然您不想像我上面那样对事情进行硬编码最佳实践通常意味着将系统属性配置与应用程序分开。 这使您可以选择使用简单的命令行参数例如 -Dspring.profiles.activetest1 …或通过添加 # Setting a property value spring.profiles.activetest1 到Tomcat的catalina.properties 所以这就是全部您可以通过使用Profile注释对Configuration进行注释来创建Spring配置文件然后通过将spring.profiles.active系统属性设置为配置文件的名称来打开要使用的配置文件 。 像往常一样Spring的伙计们不仅将您限制在使用系统属性来激活配置文件中还可以以编程方式进行操作。 例如下面的代码创建AnnotationConfigApplicationContext 然后在注册我们的Configuration类之前使用Environment对象激活“ test1”配置文件。 Test public void testAnnotationConfigApplicationContextThatWorks() { // Can register a list of config classes AnnotationConfigApplicationContext ctx new AnnotationConfigApplicationContext(); ctx.getEnvironment().setActiveProfiles(test1); ctx.register(Test1ProfileConfig.class, Test2ProfileConfig.class); ctx.refresh(); Person person ctx.getBean(employee, Person.class); String firstName person.getFirstName(); assertEquals(John, firstName); } 一切都很好但是请注意您需要以正确的顺序调用AnnotationConfigApplicationContext的方法。 例如如果您在指定配置文件之前注册Configuration类则将收到IllegalStateException 。 Test(expected IllegalStateException.class) public void testAnnotationConfigApplicationContextThatFails() { // Can register a list of config classes AnnotationConfigApplicationContext ctx new AnnotationConfigApplicationContext( Test1ProfileConfig.class, Test2ProfileConfig.class); ctx.getEnvironment().setActiveProfiles(test1); ctx.refresh(); Person person ctx.getBean(employee, Person.class); String firstName person.getFirstName(); assertEquals(John, firstName); } 在关闭今天的博客之前下面的代码演示了将多个Profiles附加到Configuration批注的功能。 Configuration Profile({ test1, test2 }) public class MulitpleProfileConfig { Bean public Person tourDeFranceWinner() { return new Person(Bradley, Wiggins, 32); } }Test public void testMulipleAssignedProfilesUsingSystemProperties() { System.setProperty(spring.profiles.active, test1); ApplicationContext ctx new ClassPathXmlApplicationContext(profiles-config.xml); Person person ctx.getBean(tourDeFranceWinner, Person.class); String firstName person.getFirstName(); assertEquals(Bradley, firstName); System.setProperty(spring.profiles.active, test2); ctx new ClassPathXmlApplicationContext(profiles-config.xml); person ctx.getBean(tourDeFranceWinner, Person.class); firstName person.getFirstName(); assertEquals(Bradley, firstName); } 在上面的代码中2012年环法自行车赛冠军布拉德利·威金斯同时出现在“ test1”和“ test2”个人资料中。   参考 Spring来自JCG合作伙伴 Roger Hughes的Enterprise Java 在Captain Debug的Blog博客中。 翻译自: https://www.javacodegeeks.com/2012/08/spring-profiles-and-java-configuration.html
http://www.pierceye.com/news/941478/

相关文章:

  • 购物网站如何备案wordpress首页自定义
  • 企业手机网站建设提升用户体验的三个点无极领域付费网站
  • 网站设计常州网站开发年度总结
  • 免费注册网站网址做网站大概要
  • 注册网站会不会有问题做网站建设的注意事项
  • 小吃培训网站源码淮南市招标投标信息网
  • 做网站申请多少类商标网站开发的案例分析模板
  • 怎么进网站后台管理系统在线二维码制作生成器
  • seo网站关键词优化多少钱陕西省建设厅网站官网
  • 仿xss网站搭建建设网站费用吗
  • 钓鱼网页在线生成网站网站建设肆金手指排名7
  • idc网站备案家具网站建设方案
  • 互联网做网站怎么赚钱WordPress副标题不显示
  • 好的网站域名网站运营推广怎做
  • 巴适网站建设wordpress上传与安装包
  • 网站备案不关站wordpress网
  • 中国佛山手机网站建设十大互联网公司排名
  • 手把手指导做网站wordpress 熊掌号插件
  • 宁波网站建设方案报价湖州企业做网站
  • 优化 导航网站百度官网网站首页
  • 各大网站大全河北网站建设seo优化制作设计
  • 做照片的网站前端开发和后端开发
  • 谁能低价做网站支付接口泰州企业自助建站系统
  • 徐州 网站建设辽阳建设网站
  • PHP MySQL 网站开发实例单页应用网站
  • 制作网站的步骤关于企业网站建设的相关思考
  • 统计局网站建设情况ppt设计网站
  • 中石化第四建设公司 网站哪个软件可以看街道实景
  • 郑州做网站哪个平台好全国网站备案
  • 个人网站空间申请html5 网站开发 适配