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

用php写的网站有哪些百度代理推广

用php写的网站有哪些,百度代理推广,小城镇建设期刊网站,浏览器网页游戏借鉴#xff1a;https://blog.csdn.net/j903829182/article/details/74906948 一、Spring Boot 启动注解说明 SpringBootApplication开启了Spring的组件扫描和Spring Boot的自动配置功能。实际上#xff0c; SpringBootApplication将三个有用的注解组合在了一起。 Spring的Co… 借鉴https://blog.csdn.net/j903829182/article/details/74906948 一、Spring Boot 启动注解说明 SpringBootApplication开启了Spring的组件扫描和Spring Boot的自动配置功能。实际上 SpringBootApplication将三个有用的注解组合在了一起。 Spring的Configuration标明该类使用Spring基于Java的配置。虽然本书不会写太多配置但我们会更倾向于使用基于Java而不是XML的配置。Spring的ComponentScan启用组件扫描这样你写的Web控制器类和其他组件才能被自动发现并注册为Spring应用程序上下文里的Bean。默认扫描SpringBootApplication 所在类的同级目录以及它的子目录。本章稍后会写一个简单的Spring MVC控制器使用Controller进行注解这样组件扫描才能找到它。Spring Boot 的 EnableAutoConfiguration 这 个 不 起 眼 的 小 注 解 也 可 以 称 为Abracadabra①就是这一行配置开启了Spring Boot自动配置的魔力让你不用再写成篇的配置了。在Spring Boot的早期版本中你需要在ReadingListApplication类上同时标上这三个注解但从Spring Boot 1.2.0开始有SpringBootApplication就行了。 二、Bean的scope scope描述了spring容器如何新建bena的实例spring的scope有以下几种通过Scope注解来实现 Singleton一个spring容器中只有一个bena的实例此为spring的默认配置全容器共享一个实例的bean。Prototype每次调用新建一个bean的实例。Requestweb项目中给每一个http request新建一个Bean实例。Session web项目中给每一个http session新建一个实例。GlobalSession这个只在portal应用中有用给每一个global http session新建一个bean实例。另外在spring batch中还有一个Scope是使用StepScope用在批处理中。 实例 定义一个Single的Bean /*** Description: 自定义Single实例* ClassName: CustomSingleService * author OnlyMate* Date 2018年9月13日 上午10:34:36 **/ Service //默认为Sinleton相当于Scope(singleton) Scope(valuesingleton) public class CustomSingleService {} 定义一个Prototype的Bean /*** Description: 自定义Prototype实例* ClassName: CustomPrototypeService * author OnlyMate* Date 2018年9月13日 上午10:34:36 **/ Service Scope(valueprototype) public class CustomPrototypeService {} Bean的Scope配置 import org.springframework.context.annotation.ComponentScan; import org.springframework.context.annotation.Configuration;/*** Description: 自定义Bean的Scope配置类 * ClassName: CustomScopConfig * author OnlyMate* Date 2018年9月13日 上午10:59:54 **/ Configuration ComponentScan(valuecom.only.mate.springboot.basic.scope) public class CustomScopConfig {} 测试类 import org.springframework.context.annotation.AnnotationConfigApplicationContext; import com.only.mate.springboot.configure.basic.CustomScopConfig;public class CustomScopeMain {public static void main(String[] args) {// AnnotationConfigApplicationContext作为spring容器接受一个配置类作为参数AnnotationConfigApplicationContext context new AnnotationConfigApplicationContext(CustomScopConfig.class);CustomSingleService cs1 context.getBean(CustomSingleService.class);CustomPrototypeService cp1 context.getBean(CustomPrototypeService.class);CustomSingleService cs2 context.getBean(CustomSingleService.class);CustomPrototypeService cp2 context.getBean(CustomPrototypeService.class);System.out.println(cs1与cs2是否相等 cs1.equals(cs2));System.out.println(cp1与cp2是否相等 cp1.equals(cp2));context.close();} } 结果 三、Bean的初始化和销毁   在我们实际开发的时候经常会遇到在bean使用之前或者之后做一些必要的操作spring 对bean的生命周期的操作提供了支持。在使用java配置和注解配置下提供如下两种方式 java配置方式使用Bean的initMethod和destroyMethod相当于xml配置的init-method和destory-method注解方式利用JSR-250的PostConstruct和PreDestroy1、增加JSR250支持 !--增加JSR250支持-- dependencygroupIdjavax.annotation/groupIdartifactIdjsr250-api/artifactIdversion1.0/version /dependency 2、使用Bean形式的bean /*** Description: 自定义Bean方式的初始化和销毁方法* ClassName: CustomBeanWay * author OnlyMate* Date 2018年9月13日 上午11:15:41 **/ public class CustomBeanWay {public CustomBeanWay() {super();System.out.println(Bean初始化构造方法 CustomBeanWay method);}public void init() {System.out.println(Bean初始化方法 init method);}public void destroy() {System.out.println(Bean销毁方法 destroy method);} } 3、使用JSR250形式的bean /*** Description: 自定义JSR250方式的初始化和销毁方法* ClassName: CustomJSR250Way * author OnlyMate* Date 2018年9月13日 上午11:15:41 **/ public class CustomJSR250Way {public CustomJSR250Way() {super();System.out.println(JSR250初始化构造方法 CustomJSR250Way method);}PostConstructpublic void init() {System.out.println(JSR250初始化方法 init method);}PreDestroypublic void destroy() {System.out.println(JSR250销毁方法 destroy method);} } 4、配置 import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.ComponentScan; import org.springframework.context.annotation.Configuration;import com.only.mate.springboot.basic.lifecycle.CustomBeanWay; import com.only.mate.springboot.basic.lifecycle.CustomJSR250Way;Configuration ComponentScan(valuecom.only.mate.springboot.basic.lifecycle) public class CustomLifeCycleConfig {Bean(initMethod init,destroyMethod destroy)public CustomBeanWay customBeanWay(){return new CustomBeanWay();}Beanpublic CustomJSR250Way customJSR250Way(){return new CustomJSR250Way();}} 5、启动 import org.springframework.context.annotation.AnnotationConfigApplicationContext;import com.only.mate.springboot.configure.lifecycle.CustomLifeCycleConfig;SuppressWarnings(unused) public class CustomLifeCycleMain {public static void main(String[] args) {// AnnotationConfigApplicationContext作为spring容器接受一个配置类作为参数AnnotationConfigApplicationContext context new AnnotationConfigApplicationContext(CustomLifeCycleConfig.class);CustomBeanWay customBeanWay context.getBean(CustomBeanWay.class);CustomJSR250Way customJSR250Way context.getBean(CustomJSR250Way.class);context.close();} } 6、效果图 可见init方法和destory方法在构造方法之后bean销毁之前执行。 四、Spring EL和资源调用   spring EL-Spring表达式语言支持在xml和注解中使用表达式类似于jsp的EL表达式语言。  spring开发中经常涉及调用各种资源的情况包含普通文件网址配置文件系统环境变量等我们可以使用  spring表达式语言实现资源的注入。  spring主要在注解Vavle的参数中使用表达式。下面演示一下几种情况 注入普通字符串注入操作系统属性注入表达式运算结果注入其他Bean的属性注入文件内容注入网址内容注入属性文件1、准备增加commons-io可简化文件相关的操作本例使用commons-io将file转换成字符串。 !--增加commons-io可简化文件相关操作-- dependencygroupIdcommons-io/groupIdartifactIdcommons-io/artifactIdversion2.3/version /dependency  2、创建文件 在resources下简历files文件夹并创建el.properties和test.txt文件 内容如下 el.properties book.authoronlymate book.nameJava is s magictest.txt 这是test.txt里面的内容很高兴认识大家 3、需被注入的bean Component public class CustomElBean {//注入普通字符串Value(其他类属性)private String another;public String getAnother() {return another;}public void setAnother(String another) {this.another another;} } 4、配置类 import java.nio.charset.Charset;import org.apache.commons.io.IOUtils; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Value; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.ComponentScan; import org.springframework.context.annotation.Configuration; import org.springframework.context.annotation.PropertySource; import org.springframework.context.support.PropertySourcesPlaceholderConfigurer; import org.springframework.core.env.Environment; import org.springframework.core.io.Resource;/*** Description: 自定义el配置类 * ClassName: CustomElConfig * author OnlyMate* Date 2018年9月13日 上午10:59:54 **/ Configuration ComponentScan(basePackagescom.only.mate.springboot.basic.el) //注入配置文件需要使用PropertySource指定文件地址若使用Value注入则要配置一个PropertySourcesPlaceholderConfigurer的bean //注意 Value(${book.name})使用的是$而不是# //注入Properties还可以从Environment中获得 PropertySource(classpath:files/el.properties) public class CustomElConfig {//注入普通字符串Value(I Love YOU!)private String normal;//注入操作系统属性Value(#{systemProperties[os.name]})private String osName;//注入表达式结果Value(#{T(java.lang.Math).random()*100.0})private double randomNumber;//注入其他的bean属性Value(#{customElBean.another})private String fromAnother;//注入文件资源Value(classpath:files/test.txt)private Resource testFile;//注入网址资源Value(http://www.baidu.com)private Resource testUrl;//注入配置文件Value(${book.name})private String bookNmame;//注入环境Autowiredprivate Environment environment;Beanpublic static PropertySourcesPlaceholderConfigurer propertyConfigure(){return new PropertySourcesPlaceholderConfigurer();}public void outputResource(){try {System.out.println(normal);System.out.println(osName);System.out.println(randomNumber);System.out.println(fromAnother);System.out.println(IOUtils.toString(testFile.getInputStream(), Charset.defaultCharset()));System.out.println(IOUtils.toString(testUrl.getInputStream(), Charset.defaultCharset()));System.out.println(bookNmame);System.out.println(environment.getProperty(book.author));}catch (Exception e){e.printStackTrace();System.out.println(e);}}} 5、启动运行 import org.springframework.context.annotation.AnnotationConfigApplicationContext; import com.only.mate.springboot.configure.el.CustomElConfig;public class CustomElMain {public static void main(String [] args){//AnnotationConfigApplicationContext作为spring容器接受一个配置类作为参数AnnotationConfigApplicationContext context new AnnotationConfigApplicationContext(CustomElConfig.class);CustomElConfig elConfig context.getBean(CustomElConfig.class);elConfig.outputResource();context.close();}} 6、效果图  五、Profile 1、基础练习 Profile为在不同环境下使用不同的配置提供了支持开发环境下的配置和生产环境下的配置不同比如数据库 通过设定Enviroment的ActiveProfiles来设定当前context需要使用的配置环境。在开发中使用Profile注解类或者方法达到在不同情况下选择实例化不同的Bean通过设定jvm的spring.profiles.active参数来设置配置环境Web项目设置在Servlet的context parameter中1、定义一个bean /*** Description: 定义一个bean* ClassName: CustomProfileBean * author OnlyMate* Date 2018年9月13日 下午4:26:22 **/ public class CustomProfileBean {private String content;public CustomProfileBean(String content) {super();this.content content;}public String getContent() {return content;}public void setContent(String content) {this.content content;} } 2、配置 /*** Description: 自定义Profile的配置类* ClassName: CustomProfileConfig * author OnlyMate* Date 2018年9月13日 下午4:27:17 **/ Configuration public class CustomProfileConfig {BeanProfile(dev)//Profile为dev时实例化devCustomProfileBeanpublic CustomProfileBean devCustomProfileBean(){return new CustomProfileBean(from development pfofile);}BeanProfile(prod)//Profile为prod时实例化prodCustomProfileBeanpublic CustomProfileBean prodCustomProfileBean(){return new CustomProfileBean(from production profile);}} 3、启动运行 /*** Description: * ClassName: CustomProfileMain * author OnlyMate* Date 2018年9月13日 下午4:26:22 **/ public class CustomProfileMain {public static void main(String [] args){//AnnotationConfigApplicationContext作为spring容器接受一个配置类作为参数AnnotationConfigApplicationContext context new AnnotationConfigApplicationContext();//先将活动的Profile设置为prodcontext.getEnvironment().setActiveProfiles(prod);//后置注册Bean配置类不然会报bean未定义的错误context.register(CustomProfileConfig.class);//刷新容器context.refresh();CustomProfileBean demoBean context.getBean(CustomProfileBean.class);System.out.println(demoBean.getContent());context.close();} } 4、效果图 2、日志信息的配置 logback-spring.xml ?xml version1.0 encodingUTF-8? configuration debugtrue!-- debugtrue设置调试模式 --!--定义日志文件的存储地址 勿在 LogBack 的配置中使用相对路径文件要以logback-spring.xml命名--springProfile nametestproperty namecatalina.base value/home/webapp/logs/spring-boot //springProfilespringProfile nameprodproperty namecatalina.base value/app/webapp/logs/spring-boot //springProfilespringProfile namedevproperty namecatalina.base valueH:/logs/spring-boot //springProfile!--springProperty scopecontext namecatalina.base sourcecatalina.base/--!-- 日志地址 --!--property namecatalina.base valueH:/logs/property--!-- 控制台输出 --appender nameSTDOUT classch.qos.logback.core.ConsoleAppenderencoder classch.qos.logback.classic.encoder.PatternLayoutEncoderpattern%d{yyyy-MM-dd HH:mm:ss.SSS} 耗时%r 日志来自%logger{50} 日志类型: %-5p 日志内容%m%n/pattern/encoder/appender!-- 按照每天生成日志文件 --appender nameDEFAULT-APPENDER classch.qos.logback.core.rolling.RollingFileAppenderFile${catalina.base}/logs/common-default.log/FilerollingPolicy classch.qos.logback.core.rolling.TimeBasedRollingPolicy!--日志文件输出的文件名 --FileNamePattern${catalina.base}/logs/common-default-%d{yyyy-MM-dd}.log/FileNamePattern!--日志文件保留天数 --MaxHistory30/MaxHistory/rollingPolicyencoder classch.qos.logback.classic.encoder.PatternLayoutEncoder!--格式化输出%d表示日期%thread表示线程名%-5level级别从左显示5个字符宽度%msg日志消息%n是换行符 --pattern%d{yyyy-MM-dd HH:mm:ss.SSS} [%thread] %-5level %logger{50} - %msg%n/pattern/encoder!--日志文件最大的大小 --triggeringPolicy classch.qos.logback.core.rolling.SizeBasedTriggeringPolicyMaxFileSize10MB/MaxFileSize/triggeringPolicy/appender!-- 按照每天生成日志文件 -- appender nameINFO-APPENDER classch.qos.logback.core.rolling.RollingFileAppenderFile${catalina.base}/logs/info-log.log/File rollingPolicy classch.qos.logback.core.rolling.TimeBasedRollingPolicy!--日志文件输出的文件名 --FileNamePattern${catalina.base}/logs/info-log-%d{yyyy-MM-dd}.log/FileNamePattern!--日志文件保留天数 --MaxHistory30/MaxHistory/rollingPolicyencoder classch.qos.logback.classic.encoder.PatternLayoutEncoder!-- 格式化输出%d表示日期%thread表示线程名%-5level级别从左显示5个字符宽度%msg日志消息%n是换行符 --pattern%d{yyyy-MM-dd HH:mm:ss.SSS} [%thread] %-5level %logger{50} - %msg%n/pattern/encoder!--日志文件最大的大小 --triggeringPolicy classch.qos.logback.core.rolling.SizeBasedTriggeringPolicyMaxFileSize10MB/MaxFileSize/triggeringPolicy/appenderlogger namecom.google.code.yanf4j levelERROR /!-- show parameters for hibernate sql 专为 Hibernate 定制 --logger nameorg.hibernate.type.descriptor.sql.BasicBinder levelTRACE /logger nameorg.hibernate.type.descriptor.sql.BasicExtractor levelDEBUG /logger nameorg.hibernate.SQL levelDEBUG /logger nameorg.hibernate.engine.QueryParameters levelDEBUG /logger nameorg.hibernate.engine.query.HQLQueryPlan levelDEBUG /!--myibatis log configure--logger nameorg.apache.ibatis levelDEBUG/logger namejava.sql.Connection levelDEBUG/logger namejava.sql.Statement levelDEBUG/logger namejava.sql.PreparedStatement levelDEBUG/logger namenet.rubyeye.xmemcached levelINFO/logger nameorg.springframework levelINFO/logger namenet.sf.ehcache levelINFO/logger nameorg.apache.zookeeper levelINFO /!-- 指定某一个包或者某一个类的打印级别以及是否传入root进行打印 --!-- addtivity:是否向上级loger传递打印信息。默认是true。--!-- loger可以包含零个或多个appender-ref元素标识这个appender将会添加到这个loger。--!-- name:用来指定受此loger约束的某一个包或者具体的某一个类。--!-- level:用来设置打印级别大小写无关TRACE, DEBUG, INFO, WARN, ERROR, ALL 和 OFF还有一个特俗值INHERITED或者同义词NULL代表强制执行上级的级别。如果未设置此属性那么当前loger将会继承上级的级别。--!-- 为所有开头为dao的类打印sql语句 --!-- logger namedao levelDEBUGappender-ref refINFO-APPENDER //logger --logger namecom.only.mate levelDEBUG additivitytrueappender-ref refINFO-APPENDER //logger!-- 也是loger元素但是它是根loger。只有一个level属性应为已经被命名为root. --root levelDEBUGappender-ref refSTDOUT/appender-ref refDEFAULT-APPENDER//root/configuration 这里有兴趣的自己自己尝试。 3、Java代码中根据系统环境处理逻辑 创建一个服务实现ApplicationContextAware接口 import org.springframework.beans.BeansException; import org.springframework.context.ApplicationContext; import org.springframework.context.ApplicationContextAware; import org.springframework.stereotype.Service;Service public class CustomProfileService implements ApplicationContextAware{private ApplicationContext applicationContext null;Overridepublic void setApplicationContext(ApplicationContext applicationContext) throws BeansException {this.applicationContext applicationContext;}public void doSomething() {//获取当前系统环境String[] springActives applicationContext.getEnvironment().getActiveProfiles();String springActive ;if(springActives.length 0) {springActive springActives[0];}else {springActive applicationContext.getEnvironment().getDefaultProfiles()[0];}System.out.println(当前的开发环境 springActive);} } 配置类 /*** Description: 自定义Profile的配置类* ClassName: CustomProfileConfig * author OnlyMate* Date 2018年9月13日 下午4:27:17 **/ Configuration ComponentScan(basePackagescom.only.mate.springboot.basic.profile) public class CustomProfileConfig {BeanProfile(dev)//Profile为dev时实例化devCustomProfileBeanpublic CustomProfileBean devCustomProfileBean(){return new CustomProfileBean(from development pfofile);}BeanProfile(prod)//Profile为prod时实例化prodCustomProfileBeanpublic CustomProfileBean prodCustomProfileBean(){return new CustomProfileBean(from production profile);}} 启动类 /*** Description: * ClassName: CustomProfileMain * author OnlyMate* Date 2018年9月13日 下午4:26:22 **/ public class CustomProfileMain {public static void main(String [] args){//AnnotationConfigApplicationContext作为spring容器接受一个配置类作为参数AnnotationConfigApplicationContext context new AnnotationConfigApplicationContext();//先将活动的Profile设置为prodcontext.getEnvironment().setActiveProfiles(prod);//后置注册Bean配置类不然会报bean未定义的错误context.register(CustomProfileConfig.class);//刷新容器context.refresh();CustomProfileBean customProfileBean context.getBean(CustomProfileBean.class);System.out.println(customProfileBean.getContent());CustomProfileService customProfileService context.getBean(CustomProfileService.class);customProfileService.doSomething();context.close();} } 效果图  转载于:https://www.cnblogs.com/onlymate/p/9641554.html
http://www.zqtcl.cn/news/828191/

相关文章:

  • 广州大型网站设计公司网站总体设计怎么写
  • 福州网站制作工具搜索引擎营销的特点是什么
  • 安徽省建设干部网站新品网络推广
  • 做网站要实名吗怎样给一个公司做网站
  • 品牌官方网站建设大航母网站建设
  • 自己做音乐网站挣钱吗网站定制公司kinglink
  • 网站建设案例新闻随州程力网站建设
  • 国外网站平台龙岩天宫山缆车收费
  • 站长工具seo综合查询是什么湖北做网站
  • 青海网站建设价格建一个免费网站的流程
  • 网站备案中 解析地址asp.net企业网站框架
  • flash里鼠标可以跟随到网站上就不能跟随了蚌埠网站建设
  • 东莞茶山网站建设网络推广方案ppt
  • 不需要写代码的网站开发软件模板之家如何免费下载
  • 购物网站模板多媒体网站开发实验报告
  • 做网站上数字快速增加上海市建设部注册中心网站
  • 义乌市网站制作青岛建设银行银行招聘网站
  • 公司网站的留言板怎么做wordpress减肥网站采集规则
  • app软件下载站seo教程wordpress实现专题
  • 在哪里自己建设网站做网站后期需要什么费用
  • 宁波网站推广怎么做微信公众号如何运营与推广
  • 做网站开发语言农产品品牌建设
  • 百度一下你就知道官方网站做准考证的网站
  • 2008 访问网站提示建设中免费asp地方门户网站系统
  • 手机网站收录wordpress无法连接ftf服务器
  • 担路网如何快速做网站安卓市场2021最新版下载
  • 自己组装电脑做网站服务器东莞市城乡和住房建设局
  • h1z1注册网站wordpress 按标题搜索
  • 院校网站建设对比分析实训报总结陕西省建设网三类人员官网
  • 嘉兴网站建设兼职企业做网站公司