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

怎么样自己做最简单的网站数字媒体艺术与ui设计相关吗

怎么样自己做最简单的网站,数字媒体艺术与ui设计相关吗,微信小程序是干什么用的,如何做好网络维护工作spring aop示例最近#xff0c;我们介绍了Spring Profiles的概念。 此概念是针对不同部署环境的轻松配置区分符。 直接的用例#xff08;已提出#xff09;是对相关的类进行注释#xff0c;以便Spring根据活动的配置文件加载适当的类。 但是#xff0c;这种方法可能并不… spring aop示例 最近我们介绍了Spring Profiles的概念。 此概念是针对不同部署环境的轻松配置区分符。 直接的用例已提出是对相关的类进行注释以便Spring根据活动的配置文件加载适当的类。 但是这种方法可能并不总是适用于常见的用例……通常配置密钥是相同的并且每个值只会随环境而变化。 在本文中我想提出一种模式来支持按环境加载配置数据 而无需为每个概要文件即针对每个环境创建/维护多个类。 在整个文章中假设每个部署环境的数据库定义例如用户名或连接URL不同我将以数据库连接配置为例。 主要思想是使用一个类来加载配置即一个类用于DB连接定义然后将适当的实例注入其中以保存正确的概要文件配置数据。 为了方便和清楚起见该过程分为三个阶段 阶段1 基础设施 步骤1.1 –创建一个包含所有配置数据的属性文件 步骤1.2 –为每个配置文件创建注释 步骤1.3 –确保在上下文加载期间加载了配置文件 阶段2 实施配置文件模式 步骤2.1 –创建属性界面 步骤2.2 –为每个配置文件创建一个类 步骤2.3 –创建一个包含所有数据的抽象文件 阶段3 使用模式 步骤3.1 –使用模式的示例 弹簧轮廓图–阶段1基础准备 此阶段将建立使用Spring Profile和配置文件的初始基础设施。 步骤1.1 –创建一个包含所有配置数据的属性文件 假设您有一个maven风格的项目请在src / main / resources / properties中为每个环境创建一个文件例如 my_company_dev.properties my_company_test.properties my_company_production.properties my_company_dev.properties内容的示例 jdbc.url jdbcmysql// localhost3306 / my_project_db db.username dev1 db.password dev1 hibernate.show_sql true my_company_production.properties内容的示例 jdbc.url jdbcmysql//10.26.26.263306 / my_project_db db.username prod1 db.password fdasjkladsof8aualwnlulw344uwj9l34 hibernate.show_sql false 步骤1.2 –为每个配置文件创建注释 在src.main.java.com.mycompany.annotation中为每个Profile创建注释例如 Target(ElementType.TYPE) Retention(RetentionPolicy.RUNTIME) Profile(DEV) public interface Dev { }Target(ElementType.TYPE) Retention(RetentionPolicy.RUNTIME) Profile(PRODUCTION) public interface Production { } 为每个配置文件创建一个枚举 公共接口MyEnums { public enum Profile{ DEV, TEST, PRODUCTION } 步骤1.3 –确保在上下文加载期间加载了配置文件 定义一个系统变量以指示代码在哪个环境中运行。 在Tomcat中转到$ {tomcat.di} /conf/catalina.properties并插入一行 profile DEV根据您的环境 定义一个类来设置活动配置文件 public class ConfigurableApplicationContextInitializer implementsApplicationContextInitializerconfigurableapplicationcontext {Overridepublic void initialize(ConfigurableApplicationContext applicationContext) {String profile System.getProperty(profile);if (profilenull || profile.equalsIgnoreCase(Profile.DEV.name())){applicationContext.getEnvironment().setActiveProfiles(Profile.DEV.name()); }else if(profile.equalsIgnoreCase(Profile.PRODUCTION.name())){applicationContext.getEnvironment().setActiveProfiles(Profile.PRODUCTION.name()); }else if(profile.equalsIgnoreCase(Profile.TEST.name())){applicationContext.getEnvironment().setActiveProfiles(Profile.TEST.name()); }} } 确保在上下文加载期间加载了该类 在项目web.xml中插入以下内容 context-paramparam-namecontextInitializerClasses/param-nameparam-valuecom.matomy.conf.ConfigurableApplicationContextInitializer/param-value /context-param 阶段2实施配置文件模式 此阶段利用我们之前构建的基础架构并实现配置文件模式。 步骤2.1 –创建属性界面 为您拥有的配置数据创建一个接口。 在我们的情况下该接口将提供对四个配置数据项的访问。 所以看起来像这样 public interface SystemStrings {String getJdbcUrl(); String getDBUsername(); String getDBPassword(); Boolean getHibernateShowSQL(); //..... 步骤2.2 –为每个配置文件创建一个类 开发配置文件示例 Dev //Notice the dev annotation Component(systemStrings) public class SystemStringsDevImpl extends AbstractSystemStrings implements SystemStrings{public SystemStringsDevImpl() throws IOException {//indication on the relevant properties filesuper(/properties/my_company_dev.properties);} } 生产资料示例 Prouction //Notice the production annotation Component(systemStrings) public class SystemStringsProductionImpl extends AbstractSystemStrings implements SystemStrings{public SystemStringsProductionImpl() throws IOException {//indication on the relevant properties filesuper(/properties/my_company_production.properties);} } 上面的两个类是属性文件与相关环境之间进行绑定的位置。 您可能已经注意到这些类扩展了一个抽象类。 这项技术很有用因此我们不需要为每个Profile定义每个getter从长远来看这是无法管理的实际上这样做是没有意义的。 蜜糖和蜂蜜位于下一步其中定义了抽象类。 步骤2.3 –创建一个包含所有数据的抽象文件 public abstract class AbstractSystemStrings implements SystemStrings{//Variables as in configuration properties file private String jdbcUrl; private String dBUsername; private String dBPassword; private boolean hibernateShowSQL;public AbstractSystemStrings(String activePropertiesFile) throws IOException {//option to override project configuration from externalFileloadConfigurationFromExternalFile();//optional..//load relevant propertiesloadProjectConfigurationPerEnvironment(activePropertiesFile); }private void loadProjectConfigurationPerEnvironment(String activePropertiesFile) throws IOException {Resource[] resources new ClassPathResource[ ] { new ClassPathResource( activePropertiesFile ) };Properties props null;props PropertiesLoaderUtils.loadProperties(resources[0]);jdbcUrl props.getProperty(jdbc.url);dBUsername props.getProperty(db.username); dBPassword props.getProperty(db.password);hibernateShowSQL new Boolean(props.getProperty(hibernate.show_sql)); }//here should come the interface getters.... 阶段3使用模式 您可能还记得在前面的步骤中我们定义了一个配置数据接口。 现在我们将在需要每个环境不同数据的类中使用该接口 。 请注意该示例是与Spring博客中给出的示例的主要区别因为现在我们不需要为每个概要文件创建一个类 因为在这种情况下我们在概要文件中使用相同的方法并且仅改变数据 。 步骤3.1 –使用模式的示例 Configuration EnableTransactionManagement //DB connection configuration class //(dont tell me youre still using xml... ;-) public class PersistenceConfig {Autowiredprivate SystemStrings systemStrings; //Spring will wire by active profileBeanpublic LocalContainerEntityManagerFactoryBean entityManagerFactoryNg(){LocalContainerEntityManagerFactoryBean factoryBean new LocalContainerEntityManagerFactoryBean();factoryBean.setDataSource( dataSource() );factoryBean.setPersistenceUnitName(my_pu); JpaVendorAdapter vendorAdapter new HibernateJpaVendorAdapter(){{// JPA propertiesthis.setDatabase( Database.MYSQL); this.setDatabasePlatform(org.hibernate.dialect.MySQLDialect);this.setShowSql(systemStrings.getShowSqlMngHibernate());//is set per environemnt.. }}; factoryBean.setJpaVendorAdapter( vendorAdapter );factoryBean.setJpaProperties( additionalProperties() );return factoryBean;} //... Beanpublic ComboPooledDataSource dataSource(){ComboPooledDataSource poolDataSource new ComboPooledDataSource();try {poolDataSource.setDriverClass( systemStrings.getDriverClassNameMngHibernate() );} catch (PropertyVetoException e) {e.printStackTrace();} //is set per environemnt..poolDataSource.setJdbcUrl(systemStrings.getJdbcUrl());poolDataSource.setUser( systemStrings.getDBUsername() );poolDataSource.setPassword( systemStrings.getDBPassword() );//.. more properties... return poolDataSource;} } 我将不胜感激和改进。 请享用 参考来自我们JCG合作伙伴 Gal Levinsky的Spring Profile模式来自Gal Levinsky的博客博客。 翻译自: https://www.javacodegeeks.com/2012/08/spring-profile-pattern-example_7.htmlspring aop示例
http://www.ihoyoo.com/news/1064.html

相关文章:

  • 公司办公网络设计方案山西seo优化公司
  • 肃宁县做网站做淘客必须有自己内部网站吗
  • 高端网站名字电商网站开发报告
  • 网页设计个人网页代码沈阳网站关键词优化做的好吗
  • 百度做网站推广多少钱上海公司注册网上核名
  • 安卓盒子 做网站wordpress新浪微博图床
  • 与企业网站做接口运营策划
  • 长沙专业网站制作wordpress主题在哪
  • phpcms 安装官网的教程更换域名后网站图片还是无法显示wordpress导出xml
  • 个人网站设计模板上海天华建筑设计有限公司代表作
  • wordpress回收站在哪wordpress皮肤
  • 在线做试卷的网站重庆网站seo排名
  • 网上家教网站开发阿里云建设网站
  • 在网站上发消息做宣传装修在线设计平台
  • 用.net core 做网站网络营销包括哪些基本内容
  • 自己买服务器可以搭建网站吗福州制作网站软件
  • 百度免费网站空间备案 网站名称 怎么改
  • 江西工程建设信息网站网站持有者和备案企业
  • 北京网站制作公司公司湖南专业seo推广
  • 以什么主题做网站好网站制作编辑软件
  • angular wordpressseo搜索优化公司报价
  • 建网站的公司南京学习网站建设的心得体会
  • 太平洋在线企业网站管理系统南阳做网站
  • 怎么做卖花的网站西安市建设工程信息网平台官网
  • 比较有名的diy制作网站什么是网络营销网络营销的内容有哪些
  • 什邡移动网站建设网站备案取消接入
  • 获得网站后台地址深圳蕾奥规划设计公司网站
  • 网站建设与管理插图电商网站设计原则
  • 米思米网站订单取消怎么做网站建设案例如何
  • 国外红色企业网站如何设定旅游网站seo核心关键词