小编ste*_*vec的帖子

使用相对于配置文件的路径引用Spring属性文件

我正在将属性从我的Spring配置文件中移动到单独的属性文件中.这包含在配置文件中

<bean class="org.springframework.beans.factory.config.PropertyPlaceHolderConfigurer">
  <property name="location" value="file:properties/${CONFIG_MODE}/service.properties" />
</bean>
Run Code Online (Sandbox Code Playgroud)

就目前而言,属性文件的位置是相对于服务器进程的当前工作目录的.

这就要求必须从特定的工作目录启动进程,更糟糕的是允许它可以获取完全不同的属性文件(当然是远程) - 例如,如果它是在工作目录设置为旧版本的服务.

我想使用相对于包含配置文件的目录的路径来引用属性文件.

看看FileSystemResource,似乎createRelative可能就是我所需要的,但我无法弄清楚如何在配置文件中使用它.

谢谢,

史蒂夫

java spring properties

13
推荐指数
2
解决办法
3万
查看次数

是否可以查看ksh函数的"来源"?

我们的ksh环境定义了几个函数.可以使用typeset -fksh命令(或functions别名)列出这些函数的名称.是否可以看到这些功能的定义(即源代码)?

这似乎是一个显而易见的问题,但我已经尝试了所有方式的参数typeset -f,没有运气.

作为一个例子(在Linux上):

$ foo()
> {
>  echo foo
> }
$ foo
foo
$ typeset -f foo
foo
$
Run Code Online (Sandbox Code Playgroud)

对于环境中默认定义的某些(但不是全部)其他函数,typeset -f 确实显示源.

更新1:Linux内核2.4.21-32正在发生这种情况

更新2:更新2:Ctrl-V给出"版本M 1993-12-28 n +" - 看起来这是一个相当旧版本,所以可能没有以下Gilles提到的修复

谢谢,史蒂夫

unix linux ksh function

8
推荐指数
2
解决办法
3445
查看次数

为.NET Core项目与.NET Framework中的System.Data.DataTable生成的JSON更改

在.NET Core项目和.NET Framework应用程序中运行时,下面的程序会生成不同的JSON.

class Program
{
    internal static readonly MediaTypeFormatter DefaultFormatter = new JsonMediaTypeFormatter
    {
        UseDataContractJsonSerializer = false,
        SerializerSettings =
        {
            NullValueHandling = NullValueHandling.Ignore,
            DateTimeZoneHandling = DateTimeZoneHandling.Utc,
            DateFormatHandling = DateFormatHandling.IsoDateFormat
        }
    };

    private static DataTable BuildTestDataTable()
    {
        var testDataTable = new DataTable();
        testDataTable.Columns.Add("Label", typeof(string));
        testDataTable.Columns.Add("Metric", typeof(decimal));
        testDataTable.Rows.Add("A", 10);
        testDataTable.Rows.Add("B", 20);
        return testDataTable;
    }

    static void Main(string[] args)
    {
        DataTable table = BuildTestDataTable();

        ObjectContent oc = new ObjectContent(table.GetType(), table, DefaultFormatter);

        Console.WriteLine(oc.ReadAsStringAsync().Result);

        Console.ReadKey();
    }
}
Run Code Online (Sandbox Code Playgroud)

.Net框架:

[{"Label":"A","Metric":10.0},{"Label":"B","Metric":20.0}]

.Net核心:

{
    "DataTable.RemotingVersion": { …
Run Code Online (Sandbox Code Playgroud)

c# json json.net .net-core

5
推荐指数
1
解决办法
566
查看次数

Swashbuckle IDocumentFilter 实现 - 如何将 ActionDescriptor.MethodInfo 链接到操作

  • 项目:ASP Net Core 2.2、Web API
  • 软件包:Swashbuckle.AspNetCore (4.0.1)

我正在编写一个实现Swashbuckle.AspNetCore.SwaggerGen.IDocumentFilter,它在我的 swagger 配置文件的路径级别添加 x-summary 值。为此,它需要访问每个 Web 方法的以下两条信息

  1. ApiDescription.ActionDescriptor.MethodInfo - 访问方法的属性
  2. Operation.Summary - 方法的 Xml 注释

看来我可以从提供给 IDocumentFilter 实现的 #1context和 #2 中获取swaggerDoc,但除了使用路径之外,我找不到链接它们的好方法。

有更简洁的方法吗?

下面是我正在做的事情的一个简化示例。

public void Apply(SwaggerDocument swaggerDoc, DocumentFilterContext context)
{
  // Create a map from path (prepended with "/") to the custom attribute
  var methodsByPath = context.ApiDescriptions
    .ToDictionary(
      m => $"/{m.RelativePath}",
      m => ((ControllerActionDescriptor)m.ActionDescriptor).MethodInfo.GetCustomAttribute<MyCustomAttribute>());

  // Add x-summary to each path
  foreach (var pathItem in swaggerDoc.Paths)
  {
    var …
Run Code Online (Sandbox Code Playgroud)

c# swagger swashbuckle asp.net-core

5
推荐指数
1
解决办法
9953
查看次数