简介 在我们之前的Asp.net mvc 开发中,一提到配置文件,我们不由的想到 web.config 和 app.config,在 core 中,我们看到了很多的变化,新的配置系统显得更加轻量级,具有更好的扩展性,并且支持多样化的数据源。 博客园对于这个的讲解很多,比如:Artche ,但是,没有点基础看老A的博客还是有些吃力的,对于老A介绍的配置,我也是看的一头雾水,在后面的文章中,我会用像我们这些菜鸟容易接受的方式,重新解释一下。 今天,我们以 appsettings.json 为例,读取一些简单的系统配置。 appsettings.json 在 第二章 中,我们在讲到EF上线文时,在 Startup.cs 添加 services.AddDbContext<ApplicationDbContext>(options => options.UseSqlServer(Configuration.GetConnectionString("SqlServerConnection"))); 已经使用到了 appsettings.json 我们添加一些简单的系统配置,来演示一下读取 appsettings.json: { "ApplicationInsights": { "InstrumentationKey": "" }, "ConnectionStrings": { "SqlServerConnection": "Server=.;Database=db_wkmvc;User ID=sa_wkmvc;Password=123456;" }, "Logging": { "IncludeScopes": false, "LogLevel": { "Default": "Debug", "System": "Information", "Microsoft": "Information" } }, "ApplicationConfiguration": { //文件上传路径 "FileUpPath": "/upload/", //是否启用单用户登录 "IsSingleLogin": "True", //允许上传的文件格式 "AttachExtension": "gif,jpg,jpeg,png,bmp,rar,zip,doc,docx,xls,xlsx,ppt,pptx,txt,flv,apk,mp4,mpg,ts,mpeg,mp3,bak,pdf", //图片上传最大值KB "AttachImagesize": 12400 } } 我们添加一个配置类 ApplicationConfiguration
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 |
1 public class ApplicationConfiguration 2 { 3 #region 属性成员 4 5 /// <summary> 6 /// 文件上传路径 7 /// </summary> 8 public string FileUpPath { get; set; } 9 /// <summary> 10 /// 是否启用单用户登录 11 /// </summary> 12 public bool IsSingleLogin { get; set; } 13 /// <summary> 14 /// 允许上传的文件格式 15 /// </summary> 16 public string AttachExtension { get; set; } 17 /// <summary> 18 /// 图片上传最大值KB 19 /// </summary> 20 public int AttachImagesize { get; set; } 21 #endregion 22 } |
在 Startup.cs 的 ConfigureServices 添加 services.Configure<ApplicationConfiguration>(Configuration.GetSection("ApplicationConfiguration")); 在Startup.cs的中添加 services.AddTransient<EWS.UI.APP.AppConfigurtaionServices>(); 添加一个领域层 AppConfigurtaionServices public class AppConfigurtaionServices { private readonly IOptions<ApplicationConfiguration> _appConfiguration; public AppConfigurtaionServices(IOptions<ApplicationConfiguration> appConfiguration) { _appConfiguration = appConfiguration; } […]
View Details原创于 【模棱博客】 Spring Webflux和Spring Web是两个完全不同的Web栈。 然而, Spring Webflux继续支持基于注解的编程模型 使用这两个堆栈定义的端点可能看起来相似,但测试这种端点的方式是相当不同的,写这样一个端点的用户必须知道哪个堆栈处于活动状态并据此制定测试。 样品端点 考虑一个基于示例注释的端点: import org.springframework.web.bind.annotation.PostMapping import org.springframework.web.bind.annotation.RequestBody import org.springframework.web.bind.annotation.RequestMapping import org.springframework.web.bind.annotation.RestController data class Greeting(val message: String) @RestController @RequestMapping("/web") class GreetingController { @PostMapping("/greet") fun handleGreeting(@RequestBody greeting: Greeting): Greeting { return Greeting("Thanks: ${greeting.message}") } } 使用Spring Web进行测试 如果Spring Boot 2启动器用于使用Spring Web作为启动器创建此应用程序,则按以下方式使用Gradle构建文件指定: compile('org.springframework.boot:spring-boot-starter-web') 那么这样一个端点的测试将会使用一个Mock web运行时,被称为Mock MVC : import org.junit.Test import org.junit.runner.RunWith import org.springframework.beans.factory.annotation.Autowired import org.springframework.boot.test.autoconfigure.web.servlet.WebMvcTest import org.springframework.test.context.junit4.SpringRunner import org.springframework.test.web.servlet.MockMvc import org.springframework.test.web.servlet.request.MockMvcRequestBuilders.post import org.springframework.test.web.servlet.result.MockMvcResultMatchers.content @RunWith(SpringRunner::class) @WebMvcTest(GreetingController::class) class GreetingControllerMockMvcTest { @Autowired lateinit var mockMvc: MockMvc @Test fun testHandleGreetings() { mockMvc .perform( post("/web/greet") .content(""" |{ |"message": "Hello Web" |} […]
View Details转自:百家号-薇薇心语 各位Javaer们,大家都在用SpringMVC吧?当我们不亦乐乎的用着SpringMVC框架的时候,Spring5.x又悄(da)无(zhang)声(qi)息(gu)的推出了Spring WebFlux。web? 不是已经有SpringMVC这么好用的东西了么,为啥又冒出个WebFlux? 这玩意儿是什么鬼? Spring WebFlux特性 特性一 异步非阻塞 众所周知,SpringMVC是同步阻塞的IO模型,资源浪费相对来说比较严重,当我们在处理一个比较耗时的任务时,例如:上传一个比较大的文件,首先,服务器的线程一直在等待接收文件,在这期间它就像个傻子一样等在那儿(放学别走),什么都干不了,好不容易等到文件来了并且接收完毕,我们又要将文件写入磁盘,在这写入的过程中,这根线程又再次懵bi了,又要等到文件写完才能去干其它的事情。这一前一后的等待,不浪费资源么? 没错,Spring WebFlux就是来解决这问题的,Spring WebFlux可以做到异步非阻塞。还是上面那上传文件的例子,Spring WebFlux是这样做的:线程发现文件还没准备好,就先去做其它事情,当文件准备好之后,通知这根线程来处理,当接收完毕写入磁盘的时候(根据具体情况选择是否做异步非阻塞),写入完毕后通知这根线程再来处理(异步非阻塞情况下)。这个用脚趾头都能看出相对SpringMVC而言,可以节省系统资源。666啊,有木有! 特性二 响应式(reactive)函数编程 如果你觉得java8的lambda写起来很爽,那么,你会再次喜欢上Spring WebFlux,因为它支持函数式编程,得益于对于reactive-stream的支持(通过reactor框架来实现的),喜欢java8 stream的又有福了。为什么要函数式编程? 这个别问我,我也不知道,或许是因为bi格高吧,哈哈,开玩笑啦。 特性三 不再拘束于Servlet容器 以前,我们的应用都运行于Servlet容器之中,例如我们大家最为熟悉的Tomcat, Jetty…等等。而现在Spring WebFlux不仅能运行于传统的Servlet容器中(前提是容器要支持Servlet3.1,因为非阻塞IO是使用了Servlet3.1的特性),还能运行在支持NIO的Netty和Undertow中。 所以,看完Spring WebFlux的新特性之后,内心五味杂陈的我,只能用一个表情来形容: 以上就是Spring WebFlux的主要的三大特性,当然,只是简单的介绍了一下,可能有些javaer对特性一中的所谓的IO模型这个还比较模糊,不要着急,下一次,咱就再介绍一下IO模型,这对后面理解这个框架是很有帮助的。Spring WebFlux是基于reactor框架之上的,reactor框架是对reactive-stream的实现,因此,后面还会详细介绍这两个东西,为了去理解Spring WebFlux框架的源码。 好啦,本篇是《深入浅出Spring Webflux系列》的第一篇,就到此结束啦。 我对自己的表现很满意,因为在没包含一行代码的情况下,居然把口水话都凑足了这么多字,哈哈。。。 另外,还是要到个歉,之前因为账号被盗,文章被人删除了,然后还乱发了几篇什么杂七杂八的广告文,问过头条客服,说不能恢复被删除的文章,这小心脏因此被伤了,所以连续半年多都没来更新了。 接下来,将更新《深入浅出Spring Webflux系列》等一系列文章,然后可能是JVM调优相关,到时候具体再看情况。 from:https://www.cnblogs.com/z-test/p/9438455.html
View Details1.在pom文件添加一行打包的配置
|
1 |
<packaging>jar</packaging> |
再添加一个spring-boot-maven-plugin打包插件
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 |
<build> <plugins> <plugin> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-maven-plugin</artifactId> <executions> <execution> <goals> <goal>repackage</goal> </goals> </execution> </executions> </plugin> </plugins> </build> |
由于我的8080端口已经被占用了 ,所以我要先改下项目端口,如果你的8080端口没被占用不需要改 打开Run/Debug Configurations对话框添加一个Maven打包配置,如图 然后运行mvn就可以生成jar包 在项目的target目录可以看到生成的jar包 打开cmd,到jar 包所在目录 运行命令 java -jar springboot-0.0.1-SNAPSHOT.jar 浏览器访问结果 使用eclipse打成jar包 1.项目右键 debug as-> Debug Configurations 点击Debug即可。 当然你也可以选择打成war包,需要把pom里的jar改成war,打包后放到Tomcat的webapp下启动Tomcat就可以了。但是必须使用1.8的jdk和8.0以上的Tomcat ,且必须配置JAVA_HOME环境变量,这里我就不演示了。 from:https://blog.csdn.net/wya1993/article/details/79582014
View Details在pom文件中,添加如下即可:
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 |
<plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-compiler-plugin</artifactId> <configuration> <source>1.8</source> <target>1.8</target> </configuration> </plugin> <plugin> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-maven-plugin</artifactId> <executions> <execution> <goals> <goal>repackage</goal> </goals> </execution> </executions> </plugin> |
from:https://blog.csdn.net/qq_18769269/article/details/83095012
View Details【1】项目内部配置文件 spring boot 启动会扫描以下位置的application.properties或者application.yml文件作为Spring boot的默认配置文件
|
1 2 3 4 |
–file:./config/ –file:./ –classpath:/config/ –classpath:/ |
即如下图所示: 以上是按照优先级从高到低的顺序,所有位置的文件都会被加载,高优先级配置内容会覆盖低优先级配置内容。 SpringBoot会从这四个位置全部加载主配置文件,如果高优先级中配置文件属性与低优先级配置文件不冲突的属性,则会共同存在—互补配置。 我们也可以通过配置spring.config.location来改变默认配置。
|
1 2 |
java -jar spring-boot-02-config-02-0.0.1-SNAPSHOT.jar --spring.config.location=D:/application.properties |
项目打包好以后,我们可以使用命令行参数的形式,启动项目的时候来指定配置文件的新位置。 指定配置文件和默认加载的这些配置文件共同起作用形成互补配置。 【2】外部配置加载顺序 SpringBoot也可以从以下位置加载配置:优先级从高到低;高优先级的配置覆盖低优先级的配置,所有的配置会形成互补配置。 1.命令行参数 所有的配置都可以在命令行上进行指定; 多个配置用空格分开; –配置项=值
|
1 2 |
java -jar spring-boot-02-config-02-0.0.1-SNAPSHOT.jar --server.port=8087 --server.context-path=/abc |
2.来自java:comp/env的JNDI属性 3.Java系统属性(System.getProperties()) 4.操作系统环境变量 5.RandomValuePropertySource配置的random.*属性值 6.jar包外部的application-{profile}.properties或application.yml(带spring.profile)配置文件 7.jar包内部的application-{profile}.properties或application.yml(带spring.profile)配置文件 8.jar包外部的application.properties或application.yml(不带spring.profile)配置文件 9.jar包内部的application.properties或application.yml(不带spring.profile)配置文件
|
1 |
由jar包外向jar包内进行寻找,优先加载待profile的,再加载不带profile的。 |
10.@Configuration注解类上的@PropertySource 11.通过SpringApplication.setDefaultProperties指定的默认属性 参考官网地址 官网图示如下: from:https://blog.csdn.net/j080624/article/details/80508606
View Details设置PHP脚本执行超时的时间有下面这样一些方法: php.ini 中限定程序的最长执行时间是 30 秒,这是由 php.ini 配置文件中的 max_execution_time 变量指定,倘若你有一个需要颇多时间才能完成的程序代码,代码会由于超时而执行失败,例如要发送很多电子邮件给大量收件者,或者要进行繁重的数据分析工作,服务器会在 30 秒后强行中止正在执行的程序,如何解决这个问题呢。 一、在php.ini里面设置 max_execution_time = 1800; 二、通过PHP的ini_set 函数设置 ini_set("max_execution_time", "1800"); 三、通过set_time_limit 函数设置 set_time_limit(1800) ; ——————— 作者:YOYOYOHUI 来源:CSDN 原文:https://blog.csdn.net/yoyoyohui/article/details/83009250 版权声明:本文为博主原创文章,转载请附上博文链接!
View Detailsyarn的简介: Yarn是facebook发布的一款取代npm的包管理工具。 yarn的特点: 速度超快。 Yarn 缓存了每个下载过的包,所以再次使用时无需重复下载。 同时利用并行下载以最大化资源利用率,因此安装速度更快。 超级安全。 在执行代码之前,Yarn 会通过算法校验每个安装包的完整性。 超级可靠。 使用详细、简洁的锁文件格式和明确的安装算法,Yarn 能够保证在不同系统上无差异的工作。 yarn的安装: 下载node.js,使用npm安装 npm install -g yarn 查看版本:yarn --version 安装node.js,下载yarn的安装程序: 提供一个.msi文件,在运行时将引导您在Windows上安装Yarn Yarn 淘宝源安装,分别复制粘贴以下代码行到黑窗口运行即可 yarn config set registry https://registry.npm.taobao.org -g yarn config set sass_binary_site http://cdn.npm.taobao.org/dist/node-sass -g yarn的常用命令: 安装yarn npm install -g yarn 安装成功后,查看版本号: yarn --version 创建文件夹 yarn md yarn 进入yarn文件夹 cd yarn 初始化项目 yarn init // 同npm init,执行输入信息后,会生成package.json文件 yarn的配置项: yarn config list // 显示所有配置项 yarn config get <key> //显示某配置项 yarn config delete <key> //删除某配置项 yarn config set <key> <value> [-g|--global] //设置配置项 安装包: yarn install //安装package.json里所有包,并将包及它的所有依赖项保存进yarn.lock yarn install […]
View Details今天把博客布置上线,运行完composer install之后,报错It is unsafe to run Dusk in production.。 这是因为安装了dusk包,当你的APP_ENV=local、testing时是本地测试环境,他就是用来检测代码的质量如何,所以不会抛出这个异常。但是当你的APP_ENV=production时,也就是你部署到线上了,这个包会暴露很多接口以及程序信息,会给你的程序带来致命的危险。 解决办法也很简单,要么在线上的时候把这个包给删除掉。要么就是在安装这个包的时候,将他放在composer.json文件的require-dev下面,在线上composer安装完毕,再运行一下
|
1 |
composer install --no-dev |
问题解决。 from:https://www.guangsky.com/article/1
View Details通过 git clone 下来的 laravel 项目,因为 .gitignore 文件设置了忽略项的原因,没有/vendor目录和 /node_modules,所以直接跑是肯定跑不起来的。这时候,就需要还原 laravel 项目。 首先进入 clone 下来的项目文件 1、还原 vendor 目录
|
1 |
composer install |
2、还原 node_modules 目录
|
1 |
npm install |
或者(使用了淘宝源的话)
|
1 |
cnpm install |
3、还原 .env
|
1 2 |
cp .env.example .env php artisan key:generate |
接着按照自身情况配置 .env 4、还原 homestead.yaml
|
1 |
php vendor/bin/homestead make |
5、启动 homestead
|
1 |
vagrant up |
6、还原数据库
|
1 2 3 4 |
vagrant ssh cd XXXX php artisan migrate php artisan db:seed |
这样就恢复了 laravel 项目。 作者:Arnold_Z 链接:https://www.jianshu.com/p/dd16a9d499b9 来源:简书 简书著作权归作者所有,任何形式的转载都请联系作者获得授权并注明出处。
View Details