小编Fed*_*zza的帖子

如何使用lambda表达式调试stream().map(...)?

在我们的项目中,我们正在迁移到Java 8,我们正在测试它的新功能.

在我的项目中,我使用Guava谓词和函数来使用Collections2.transform和过滤和转换一些集合Collections2.filter.

在这次迁移中,我需要将例如guava代码更改为java 8更改.所以,我正在做的改变是这样的:

List<Integer> naturals = Lists.newArrayList(1,2,3,4,5,6,7,8,9,10,11,12,13);

Function <Integer, Integer> duplicate = new Function<Integer, Integer>(){
    @Override
    public Integer apply(Integer n)
    {
        return n * 2;
    }
};

Collection result = Collections2.transform(naturals, duplicate);
Run Code Online (Sandbox Code Playgroud)

至...

List<Integer> result2 = naturals.stream()
    .map(n -> n * 2)
    .collect(Collectors.toList());
Run Code Online (Sandbox Code Playgroud)

使用guava我调试代码非常容易,因为我可以调试每个转换过程,但我关心的是如何调试例如.map(n -> n*2).

使用调试器我可以看到一些代码,如:

@Hidden
@DontInline
/** Interpretively invoke this form on the given arguments. */
Object interpretWithArguments(Object... argumentValues) throws Throwable {
    if (TRACE_INTERPRETER)
        return interpretWithArgumentsTracing(argumentValues);
    checkInvocationCounter();
    assert(arityCheck(argumentValues));
    Object[] …
Run Code Online (Sandbox Code Playgroud)

java debugging lambda java-8

104
推荐指数
5
解决办法
6万
查看次数

如何以编程方式覆盖Spring-boot application.properties

我有来自外部配置web-service的jdbc属性文件在spring boot中为了设置mysql道具,将它们添加到application.properties很容易:

spring.datasource.url=jdbc:mysql://localhost/mydb
spring.datasource.username=root
spring.datasource.password=root
spring.datasource.driver-class-name=com.mysql.jdbc.Driver
Run Code Online (Sandbox Code Playgroud)

我怎么能在我的应用程序中重写那些程序?

Spring-batch道具同样如此:

database.driver=com.mysql.jdbc.Driver
database.url=jdbc:mysql://localhost/mydv
database.username=root
database.password=root
Run Code Online (Sandbox Code Playgroud)

spring spring-batch spring-batch-admin spring-boot

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

如何在AngularJS中使用ng-repeat动态生成ng-model ="my _ {{$ index}}"?

我想问你是否可以帮我解决这个问题.

我在这里创建了一个问题jsfiddle .我需要使用ng-model ="my _ {{$ index}}"的方式在ng-repeater中使用ng-model动态生成一些输入.

在jsfiddle中,你可以看到它运行正常,直到我尝试动态生成它.

HTML将是:

<div ng-app>
<div ng-controller="MainCtrl">
<table border="0" cellpadding="0" cellspacing="0" width="100%">
  <tr>
    <td>
      <select ng-model="selectedQuery" 
        ng-options="q.name for q in queryList" >
        <option title="---Select Query---" value="">---Select Query---</option>
      </select>
    </td>
  </tr>
  <tr ng-repeat="param in parameters">
    <td>{{param}}:</td>
    <td><input type="text" ng-model="field_X" />field_{{$index}}</td>
  </tr>
</table>
<div>
<div>
Run Code Online (Sandbox Code Playgroud)

和javascript ...

function MainCtrl($scope) {
 $scope.queryList = [
    { name: 'Check Users', fields: [ "Name", "Id"] },
    { name: 'Audit Report', fields: [] },
    { name: 'Bounce Back Report', …
Run Code Online (Sandbox Code Playgroud)

javascript angularjs ng-repeat

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

(*SKIP)或(*F)如何处理正则表达式?

我正在学习正则表达式的高级用法,并注意到许多帖子使用(*SKIP)(*F)在其中.

我发布了一个问题,其中的想法是匹配没有yellowblue只有brown在蓝色之后存在的行.正确的答案是:

.*yellow.*(*SKIP)(*F)|^.*\bblue\b(?=.*brown).*$
Run Code Online (Sandbox Code Playgroud)

我也尝试了下面的外观表达式但是并没有适用于所有情况:

^((?!yellow).)*blue(?=.*brown).*$
Run Code Online (Sandbox Code Playgroud)

我不知道这些(*SKIP)(*F)标志,所以问题是,这些标志如何工作?他们在做什么?还有其他这样的旗帜吗?

谢谢.

regex

26
推荐指数
2
解决办法
5024
查看次数

Spring + AspectJ使用aspectj-maven-plugin编织java 8

我正在将我的项目从java 7迁移到java 8,我遇到的问题与使用aspectj编织有关aspectj-maven-plugin.

根据Haus文档,我可以使用在Java 6和7上运行的这个插件成功配置编织.但问题是我还没有找到任何方法来使用(并找到)支持java 8的插件版本7.我在这里看到插件7增加了java 8支持,但找不到使用它的方法.

这是我需要的配置插件:

<plugin>
    <groupId>org.codehaus.mojo</groupId>
    <artifactId>aspectj-maven-plugin</artifactId>
    <version>1.7</version> <!-- AspectJ weaver plugin 7 is for java 8 (version 1.6 is for java 7) -->
          <configuration>
              <complianceLevel>1.8</complianceLevel>
              <source>1.8</source>
              <target>1.8</target>
          </configuration>
    <executions>
        <execution>
            <goals>
                <goal>compile</goal>
                <goal>test-compile</goal>
            </goals>
        </execution>
    </executions>
</plugin>
Run Code Online (Sandbox Code Playgroud)

我确认使用版本1.6的上述代码适用于Java 7,但没有运气试图使用1.7版.

你知道如何运行在Java 8上运行的spring + aspectj的weaver吗?

java spring aspectj java-8 aspectj-maven-plugin

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

FlywayException:无法扫描位置中的SQL迁移:classpath:db/migration

我正在尝试使用maven集成的flyway,但无法使其工作.

我跟着文档似乎很简单所以似乎没有什么奇怪的事情要做.

我的pom.xml如下:

<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
  <modelVersion>4.0.0</modelVersion>
  <groupId>com.test</groupId>
  <artifactId>test</artifactId>
  <version>0.0.1-SNAPSHOT</version>


  <build>
        <plugins>
            <!-- Flyway plugin configuration -->
            <plugin>
                <groupId>org.flywaydb</groupId>
                <artifactId>flyway-maven-plugin</artifactId>
                <version>3.0</version>
                <configuration>
                    <url>jdbc:mysql://localhost:3306/test</url>
                    <user>test_fede</user>
                    <password>test_fede</password>
                </configuration>
                <dependencies>
                    <dependency>
                        <groupId>mysql</groupId>
                        <artifactId>mysql-connector-java</artifactId>
                        <version>5.1.21</version>
                    </dependency>
                </dependencies>
            </plugin>
        </plugins>
    </build>

  <dependencies>
        <dependency>
            <groupId>com.google.guava</groupId>
            <artifactId>guava</artifactId>
            <version>13.0.1</version>
        </dependency>

        <!-- DB dependencies -->
        <dependency>
            <groupId>mysql</groupId>
            <artifactId>mysql-connector-java</artifactId>
            <version>5.1.21</version>
        </dependency>

        <!-- Test dependencies -->
        <dependency>
            <groupId>junit</groupId>
            <artifactId>junit</artifactId>
            <version>4.8.1</version>
            <scope>compile</scope>
        </dependency>
  </dependencies>
</project>
Run Code Online (Sandbox Code Playgroud)

我有目录resources/db/migration /,还没有任何迁移.

当我发出flyway:关于cygwin或cmd的信息时,我遇到了一个飞路错误:

$ mvn compile flyway:info
[INFO] Scanning for projects... …
Run Code Online (Sandbox Code Playgroud)

java database maven flyway

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

Spring启动嵌入式tomcat日志

我正在使用spring boot嵌入式tomcat和spring boot 1.5.9,我也使用Log4j2.

最近我加载期间的exerience问题,所以我想更好地了解tomcat日志[不是访问日志],我试过(在application.properties中):

logging.level.org.apache.tomcat: INFO
logging.level.org.apache.catalina: INFO
Run Code Online (Sandbox Code Playgroud)

但上述都没有奏效.有没有其他方法来实现它?

logging spring tomcat8 spring-boot embedded-tomcat-8

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

如何使用Flyway配置来处理多个数据库

我们有一个使用maven配置的java应用程序,它使用多个数据库.这是一个应用程序 - 许多架构.

我已经配置了flyway,经过测试并且运行良好,但我的配置仅适用于一个数据库.

这是我用一个模式测试的pom.xml:

<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
  <modelVersion>4.0.0</modelVersion>
  <groupId>com.test</groupId>
  <artifactId>test</artifactId>
  <version>0.0.1-SNAPSHOT</version>


  <build>
        <plugins>
            <!-- Flyway plugin configuration -->
            <plugin>
                <groupId>org.flywaydb</groupId>
                <artifactId>flyway-maven-plugin</artifactId>
                <version>3.0</version>
                <configuration>
                    <url>jdbc:mysql://localhost:3306/argentina</url>
                    <user>test</user>
                <password>test</password>
                </configuration>
                <dependencies>
                    <dependency>
                <groupId>mysql</groupId>
                <artifactId>mysql-connector-java</artifactId>
                <version>5.1.21</version>
            </dependency>
                </dependencies>
            </plugin>
        </plugins>
    </build>

  <dependencies>
        <dependency>
              <!-- alllll my dependency list -->
        </dependency>

        <!-- DB dependencies -->
        <dependency>
            <groupId>mysql</groupId>
            <artifactId>mysql-connector-java</artifactId>
            <version>5.1.21</version>
        </dependency>

  </dependencies>
</project>
Run Code Online (Sandbox Code Playgroud)

更新:通过使用现在提供的答案,我有以下pom.xml配置了2个架构.

<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
  <modelVersion>4.0.0</modelVersion>
  <groupId>com.test</groupId>
  <artifactId>test</artifactId>
  <version>0.0.1-SNAPSHOT</version>


  <build>
        <plugins>
            <plugin>
            <groupId>org.flywaydb</groupId>
                <artifactId>flyway-maven-plugin</artifactId>
                <version>3.0</version>
                <executions>
                    <execution>
                        <id>argentina</id>
                        <phase>compile</phase> …
Run Code Online (Sandbox Code Playgroud)

java database database-migration maven flyway

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

为什么RestTemplate GET响应是在JSON中应该是XML?

我使用RestTemplate(org.springframework.web.client.RestTemplate)挣扎于一个额外的弹簧行为而没有成功.

我在代码下面的我的洞应用程序中使用并始终接收XML响应,我解析并评估其结果.

String apiResponse = getRestTemplate().postForObject(url, body, String.class);
Run Code Online (Sandbox Code Playgroud)

但无法弄清楚为什么服务器响应在执行后呈JSON格式:

String apiResponse = getRestTemplate().getForObject(url, String.class);
Run Code Online (Sandbox Code Playgroud)

我在低级RestTemplate调试,内容类型是XML,但不知道为什么结果是在JSON中.

当我从浏览器访问时,响应也是XML格式,但在apiResponse中我得到了JSON.

我试过很多选择阅读Spring文档后 http://docs.spring.io/spring/docs/3.0.x/api/org/springframework/web/client/RestTemplate.html

还试图明确修改标题但仍然无法搞清楚.

我调试了RestTemplate类,并注意到这个方法总是设置application/json:

public void doWithRequest(ClientHttpRequest request) throws IOException {
            if (responseType != null) {
                List<MediaType> allSupportedMediaTypes = new ArrayList<MediaType>();
                for (HttpMessageConverter<?> messageConverter : getMessageConverters()) {
                    if (messageConverter.canRead(responseType, null)) {
                        List<MediaType> supportedMediaTypes = messageConverter.getSupportedMediaTypes();
                        for (MediaType supportedMediaType : supportedMediaTypes) {
                            if (supportedMediaType.getCharSet() != null) {
                                supportedMediaType =
                                        new MediaType(supportedMediaType.getType(), supportedMediaType.getSubtype());
                            }
                            allSupportedMediaTypes.add(supportedMediaType);
                        }
                    }
                }
                if (!allSupportedMediaTypes.isEmpty()) {
                    MediaType.sortBySpecificity(allSupportedMediaTypes);
                    if (logger.isDebugEnabled()) {
                        logger.debug("Setting …
Run Code Online (Sandbox Code Playgroud)

java rest spring resttemplate

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

UnknownHostException kafka

我正在尝试设置Kafka集群(实际上是集群中的第一个节点).

我有一个单节点zookeeper群集设置.我在一个单独的节点上设置kafka.

两者都运行CentOS 6.4,运行IPV6,这是一个PITA.我验证了这些机器可以使用netcat相互通信.

当我启动kafka时,我收到以下异常(导致kafka关闭).编辑:我开始kafka,我不得不host.name在server.config文件中设置属性.

我能够创建一个测试主题并从kafka服务器发送消息.

但是,尝试使用消息时出现相同的错误.

任何帮助,建议?

host.name

apache-kafka apache-zookeeper

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