小编Den*_*Ich的帖子

从ps -ef | grep关键字获取pids

我想用来ps -ef | grep "keyword"确定一个守护进程的pid(ps -ef的输出中有一个唯一的字符串).

我可以用pkill keyword任何命令返回pid而不是杀死它来杀死进程吗?(pidof或pgrep不起作用)

linux shell daemon

103
推荐指数
6
解决办法
16万
查看次数

Spring应用程序上下文外部属性

我有一个Spring应用程序,它到目前为止运行良好.现在我希望属性文件在外部配置文件夹中,而不是在打包的jar中更改内容而无需重新打包.这就是我得到的:

<bean class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
<!-- <property name="locations" value="classpath:/springcontext.properties"/>  -->
<property name="locations" value ="config/springcontext.properties" />
Run Code Online (Sandbox Code Playgroud)

经过评估的一个正在工作,而另一个我没有工作:/有人可以帮忙吗?

编辑:Thx 4评论到目前为止.

也许我的问题不够清楚:).我执行一个Maven构建,一切都将打包,我希望这个文件夹不在outcomming jar旁边的包装螺母中,在这个文件夹中我想要属性文件.可能?

spring properties

29
推荐指数
5
解决办法
10万
查看次数

在Spring MVC中扩展带注释的控制器

我正在开发一个小项目,并且有一些现有的代码,我希望保持清除我的更改,因此我需要扩展一个带注释的控制器,但这不起作用:

package a;

@controller
public class BaseController {
    // Autowired fields

    protected x toExtend() {
         // do stuff
    }

    @RequestMapping(value = "/start")
    protected ModelAndView setupForm(...) {
        toExtend();
        // more stuff
    }
}



package b;

@controller
public class NewController extends BaseController {
    // Autowired fields

    @Override
    protected x toExtend() {
         super.toExtend();
         //new stuff
    }
}
Run Code Online (Sandbox Code Playgroud)

扫描包a和b扫描控制器,我不能改变它.我真的不希望这个工作,因为@RequestMapping(value ="/ start")在两个控制器中都是冗余的.因此我得到了一个例外.

所以我的问题是,实际上是否可以在不更改BaseController的情况下扩展这样的注释驱动控制器?

java spring-mvc

9
推荐指数
1
解决办法
3万
查看次数

Spring Profiles,不同的Log4j2配置

在我的application.yml中,我得到了:

logging: 
  config: classpath:log4j2.debug.yml
Run Code Online (Sandbox Code Playgroud)

以及其他一些不同的配置文件.当我启动应用程序时,我得到以下内容:

ERROR StatusLogger No log4j2 configuration file found. Using default configuration: logging only errors to the console.
Run Code Online (Sandbox Code Playgroud)

如果我只是将log4j2.xml放在配置文件的旁边,那就可以了.所以我认为这是一个我错过了依赖性的东西,或者用log4j2是不可能的?

参考:引导记录级别说我应该可以试试吗?

spring log4j2 spring-boot

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

测试 Spring Boot 库模块

我有一个多模块项目,其中并非每个模块实际上都是应用程序,但其中很多都是库。这些库正在完成主要工作,我想在它们的实现位置测试它们。库的当前依赖项:

implementation 'org.springframework.boot:spring-boot-starter'
testImplementation 'org.springframework.boot:spring-boot-starter-test'
Run Code Online (Sandbox Code Playgroud)

在主要源代码中是一个带有@Configuration单个 bean 的类:

@Bean public String testString() { return "A Test String"; }
Run Code Online (Sandbox Code Playgroud)

我有2个测试班:

@RunWith(SpringRunner.class)
@SpringBootTest
@ActiveProfiles({"default", "test"}) 
public class Test1 {  

    @Test
    public void conextLoaded() {
    }
}
Run Code Online (Sandbox Code Playgroud)

-

@RunWith(SpringRunner.class)
@SpringBootTest
@ActiveProfiles({"default", "test"}) 
public class Test2 {  
    @Autowired
    private String testString; 

    @Test
    public void conextLoaded() {
    }
}
Run Code Online (Sandbox Code Playgroud)

第一次测试有效。第二个没有。该项目中没有@SpringBootApplication任何地方,因此在与测试相同的包中我添加了测试配置:

@SpringBootConfiguration
@EnableAutoConfiguration
@ComponentScan("com.to.config") 
public class LibTestConfiguration {
}
Run Code Online (Sandbox Code Playgroud)

但它不起作用。对于 的类也是如此@Service。它们不在上下文中。我怎样才能让它像一个普通的 Spring boot 应用程序一样运行,而不需要它真正成为一个应用程序并从我需要的配置文件中加载配置和上下文?默认配置文件和测试配置文件共享它们的大部分属性(目前),我希望它们像启动 tomcat 一样加载。

java spring automated-tests unit-testing spring-boot

8
推荐指数
1
解决办法
8029
查看次数

Java可选的评估副作用

我在评估Java选项时遇到了一些麻烦.考虑以下测试:

@Test
public void test() {
    System.out.println("GOT STRING: " + first().orElse(second()));
}

private Optional<String> first() {
    System.out.println("Evaluating first");
    return Optional.of("STRING OPTIONAL");
}

private String second() {
    System.out.println("Evaluating second");
    return "SECOND STRING";
}
Run Code Online (Sandbox Code Playgroud)

我的期望是,因为first()返回非空的Optional,所以不评估第二个.但事实上输出是:

Evaluating first
Evaluating second
GOT STRING: STRING OPTIONAL
Run Code Online (Sandbox Code Playgroud)

尝试在测试中使用orElse中使用的函数:

@Test
public void test2() {
    System.out.println("GOT STRING: " + (first() != null ? "FIRST IS NOT NULL" : second()));
}
Run Code Online (Sandbox Code Playgroud)

输出:

Evaluating first
GOT STRING: FIRST IS NOT NULL
Run Code Online (Sandbox Code Playgroud)

为什么评估第二个选项?这似乎很糟糕?

java lambda

6
推荐指数
2
解决办法
739
查看次数

从iframe中的String显示XML作为XMLTree

我从gwt rpc调用获得了一个XML String,我希望将其作为xml页面嵌入到iframe中.我希望看到的是漂亮的打印xml树,它的可折叠结构是浏览器提供的普通html内容.所以说一个xml的inpage视图.

我不能使用iframe的srcdoc属性,因为它不支持IE8(最早需要支持),而下一个问题是不允许使用javascript库.

我尝试了什么:

var iframeDocument = document.querySelector('#foo').contentWindow.document;
iframeDocument.open('text/xml', 'replace'); // Also tested without Args
iframeDocument.write(xmlcontent);
iframeDocument.close();
Run Code Online (Sandbox Code Playgroud)

虽然Firefox至少显示XML标签,但没有格式化,没有树Chrome和IE删除html标签,只是排列内容.

我试过的东西是

<iframe id="xmlframe" src="test.xml" name="thexml">
Run Code Online (Sandbox Code Playgroud)

在这里Firefox完全符合我的要求,而其他产生与以前相同的输出.所以这也没有用,我没有test.xml我只有一个字符串变量以及返回的其他东西...

这甚至可能吗?如果不是,您将如何使用xml String作为内容打开新的弹出窗口?

html javascript xml iframe

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

将多个参数传递给React中的事件处理程序

所以我试图使反应与ES6语法一起工作.在ES5中,我有setInitialState,没有使用函数绑定语法的构造函数.我有一个价格列表是任意的,我希望状态在输入元素改变时改变.但是必须改变合适的价格.

我甚至不确定这是正确的做法.有人可以告诉我这应该做的最新方式吗?

这是我的代码:

import React, {Component} from 'react'
import 'bootstrap/dist/css/bootstrap.css';

export default class PriceTable extends Component {
  constructor(props, context) {
    super(props, context);

    this.state = {
      pid: this.props.pid || "12345",
      name: this.props.name || "name",
      prices: this.props.prices || [
        {count: 1, desc: 'one', price: 8.25},
        {count: 6, desc: 'six', price: 7.60},
        {count: 12, desc: 'twelve', price: 6.953}
      ]
    };

    this.setPid = this.setPid.bind(this);
    this.setName = this.setName.bind(this);
    this.setCount = this.setCount.bind(this, i);
    this.setDesc = this.setDesc.bind(this, i);
    this.setPrice = this.setPrice.bind(this, i);
    this.logDebug = this.logDebug.bind(this);
  }

  setPid(e) …
Run Code Online (Sandbox Code Playgroud)

reactjs twitter-bootstrap-3

4
推荐指数
1
解决办法
1万
查看次数

Elasticsearch 按地理位置聚合

我想用形状和边界框按位置对数据进行分组。例如按半球对结果进行分组:

GET cdc/_search
{
   "from": 0,
   "size": 0,
   "query": {
      "match_all": {}
   },
   "aggs": {
      "group_by_geo": {
         "geo_bounding_box": {
            "field": "location",
            "boxes": [
               {
                  "top_left": {
                     "lat": 90,
                     "lon": -180
                  },
                  "bottom_right": {
                     "lat": 0,
                     "lon": 0
                  }
               },
               {
                  "top_left": {
                     "lat": 90,
                     "lon": 0
                  },
                  "bottom_right": {
                     "lat": 0,
                     "lon": 180
                  }
               },
               {
                  "top_left": {
                     "lat": 0,
                     "lon": -180
                  },
                  "bottom_right": {
                     "lat": -90,
                     "lon": 0
                  }
               },
               {
                  "top_left": {
                     "lat": 0,
                     "lon": 0
                  },
                  "bottom_right": …
Run Code Online (Sandbox Code Playgroud)

search search-engine elasticsearch

2
推荐指数
1
解决办法
183
查看次数