我有一个maven多模块项目,我正在使用jacoco-maven进行代码覆盖率报告.不应该报告某些类,因为它们是Spring配置,我对它们不感兴趣.
我已经宣布了maven-jacoco插件如下:
<plugin>
<groupId>org.jacoco</groupId>
<artifactId>jacoco-maven-plugin</artifactId>
<version>0.7.2.201409121644</version>
<configuration>
<outputDirectory>${project.reporting.outputDirectory}/jacoco-ut</outputDirectory>
<exclude>some.package.*</exclude>
<exclude>**/*Config.*</exclude>
<exclude>**/*Dev.*</exclude>
<exclude>some/package/SomeClass.java</exclude>
</configuration>
<executions>
<execution>
<goals>
<goal>prepare-agent</goal>
</goals>
</execution>
<execution>
<id>report</id>
<phase>prepare-package</phase>
<goals>
<goal>report</goal>
</goals>
</execution>
<execution>
<id>post-unit-test</id>
<phase>test</phase>
<goals>
<goal>report</goal>
</goals>
</execution>
</executions>
</plugin>
Run Code Online (Sandbox Code Playgroud)
问题是,当我执行mvn clean verifyjacoco时,仍会报告应该已被排除的类,因为我的xml配置指出了.如何正确配置?
我想定义一个Date#next第二天返回的实例方法.所以我做了一个DateExtension模块,像这样:
module DateExtension
def next(symb=:day)
dt = DateTime.now
{:day => Date.new(dt.year, dt.month, dt.day + 1),
:week => Date.new(dt.year, dt.month, dt.day + 7),
:month => Date.new(dt.year, dt.month + 1, dt.day),
:year => Date.new(dt.year + 1, dt.month, dt.day)}[symb]
end
end
Run Code Online (Sandbox Code Playgroud)
使用它:
class Date
include DateExtension
end
Run Code Online (Sandbox Code Playgroud)
调用该方法d.next(:week)会使Ruby抛出错误ArgumentError: wrong number of arguments (1 for 0).如何使用模块中声明的next方法覆盖Date类中的默认方法DateExtension?
我想仅使用不可变对象构建我的域模型.但我也想使用具有val字段的特征并将一些功能移到特征中.请看下面的例子:
trait Versionable {
val version = 0
def incrementVersion = copy(version=version+1)
}
Run Code Online (Sandbox Code Playgroud)
不幸的是这样的代码不起作用 - 对于特性Versionable,复制方法是未知的.
我认为为每个特征和类生成复制方法会很好.这样的方法应该创建对象的浅拷贝,并使用与原始对象相同的类型返回它,并根据传递给方法的参数修改给定的字段.
所以在下面的例子中:
class Customer(val name: String) extends Versionable {
def changeName(newName: String) = copy(name = newName)
}
val customer = new Customer("Scot")
Run Code Online (Sandbox Code Playgroud)
customer.changeName("McDonnald") 应该返回一个对象实例 Customer(version = 0, name = "McDonnald")
和
customer.incrementVersion 还应该返回一个对象实例 Customer(version = 1, name = "Scot")
据我所知,目前Scala中缺少此类功能不允许使用不可变类和特征而不会污染具有特征字段的类构造函数.在我的示例中,我不想将参数命名版本引入Customer类,因为版本处理的功能我想要封装在Versionable特性中.
我知道案例类中复制方法的功能以及使用默认参数在类中编写自己的复制方法的能力 - 但我认为这个功能并不能解决我的问题,因为在特征中不可能使用这种复制方法.现有功能的另一个缺点是使用复制方法的父类返回父类而不是实际复制的对象类.
我的问题:
1)您是否知道如何以优雅的方式处理上述示例.我对Scala很新,所以也许已经有了很好的解决方案.在我看来,优雅的解决方案应具有以下功能:
不应该使用反射
不应该使用序列化
应该快
应该在编译时可以验证
2)您如何考虑编写编译器插件来为我上面的示例生成复制方法的代码?是否可以使用编译器插件来做到这一点?您有任何示例或提示如何做到这一点?
通过阅读12factor中的以下帖子,我想出了一个问题,我想检查一下你们如何处理这个问题.
基本上,应用程序应直接写入stdout/stderr.反正将这些流直接重定向到流畅(不绑定到rsyslog/syslog)?随着我越来越清楚流利,我相信它将成为来自多个应用/平台的日志聚合的绝佳工具.
这样做的主要原因是,如果应用程序是跨平台的,则rsyslog/syslog可能不可用,并且据我所知,使用日志框架(需要使用它们所需的配置)将违反12factor.
谢谢!
我正在关注此链接以安装Oracle Java 8.
也许我弄错了,但我想安装后应该设置JAVA_HOME oracle-java8-set-default.
如果我echo $JAVA_HOME或printenv | grep -i java什么都没有出现.我正在使用Linux Mint 17.1(Rebecca)
谢谢!
我正在尝试设置一个由MySQL数据库容器支持的SonarQube容器.我的docker-compose.yml:
sonar:
environment:
- SONARQUBE_USER=sonar
- SONARQUBE_PASSWORD=sonar
- SONARQUBE_DATABASE=sonar
- SONARQUBE_JDBC_URL=jdbc:mysql://db:3306/sonar?useUnicode=true&characterEncoding=utf8
build: .
ports:
- "19000:9000"
- "19306:3306"
links:
- db
db:
environment:
- MYSQL_ROOT_PASSWORD=root-secret
- MYSQL_USER=sonar
- MYSQL_PASSWORD=sonar
- MYSQL_DATABASE=sonar
image: mysql
Run Code Online (Sandbox Code Playgroud)
在本ports节中,我试图从SonarQube(Web界面)和端口3306(MySQL连接)公开端口9000.
有没有办法db从"主"容器中公开链接服务(例如在这种情况下)的端口,例如sonar?
编辑:为了更好地解释我的需求,我想将两个端口暴露给我localhost.我需要从我的机器访问这两个端口,因为我的SonarQube运行器需要访问数据库,我也想在数据库中运行一些查询,从我的机器,而不是在另一个容器内.
首先,我想指出我不太了解Spring Security,实际上我对它的接口和类知之甚少,但是我做了一个不那么简单的任务,无法弄明白.我的代码基于Spring安全论坛的以下帖子(我没有和帖子所有者一样的问题):http: //forum.spring.io/forum/spring-projects/security/747178-security-过滤器链是-总是主叫的AuthenticationManager-两次每次请求
我正在编写一个Spring MVC系统,它将提供HTTP内容,但为了做到这一点,它有一个preauth检查(我目前正在使用带有自定义AuthenticationManager的RequestHeaderAuthenticationFilter).
为了授权用户,我将针对两个来源检查令牌,即Redis缓存"数据库"和Oracle.如果在任何这些源中找不到令牌,我的自定义AuthenticationManager的authenticate方法会抛出BadCredentialsException(我认为它遵循AuthenticationManager合同).
现在我想返回HTTP响应401 - 未经授权,但Spring不断返回500 - 服务器错误.是否可以自定义我的设置以仅返回401而不是500?
这是相关的代码:
SecurityConfig - 主要的弹簧安全配置
package br.com.oiinternet.imoi.web.config;
import javax.validation.constraints.NotNull;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.boot.autoconfigure.security.SecurityProperties;
import org.springframework.context.ApplicationContext;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.core.annotation.Order;
import org.springframework.http.HttpMethod;
import org.springframework.security.authentication.AuthenticationManager;
import org.springframework.security.config.annotation.web.builders.HttpSecurity;
import org.springframework.security.config.annotation.web.configuration.EnableWebSecurity;
import org.springframework.security.config.annotation.web.configuration.WebSecurityConfigurerAdapter;
import org.springframework.security.config.http.SessionCreationPolicy;
import org.springframework.security.web.AuthenticationEntryPoint;
import org.springframework.security.web.access.AccessDeniedHandler;
import org.springframework.security.web.access.AccessDeniedHandlerImpl;
import org.springframework.security.web.authentication.Http403ForbiddenEntryPoint;
import org.springframework.security.web.authentication.logout.LogoutFilter;
import org.springframework.security.web.authentication.preauth.RequestHeaderAuthenticationFilter;
@Configuration
@EnableWebSecurity
@Order(SecurityProperties.ACCESS_OVERRIDE_ORDER)
public class SecurityConfig extends WebSecurityConfigurerAdapter {
private static final Logger LOG = LoggerFactory.getLogger(SecurityConfig.class); …Run Code Online (Sandbox Code Playgroud) 我正在尝试使用maven支持设置SonarQube(v.4.5.6).我相信我的配置是正确的,但我不能让SonarQube分析运行没有错误.
我的项目依赖项:
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-actuator</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
<exclusions>
<exclusion>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-tomcat</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-jetty</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-security</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.security</groupId>
<artifactId>spring-security-ldap</artifactId>
</dependency>
<dependency>
<groupId>org.apache.httpcomponents</groupId>
<artifactId>httpclient</artifactId>
<exclusions>
<exclusion>
<artifactId>commons-logging</artifactId>
<groupId>commons-logging</groupId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-redis</artifactId>
</dependency>
<dependency>
<groupId>com.google.guava</groupId>
<artifactId>guava</artifactId>
<version>${guava.version}</version>
</dependency>
<dependency>
<groupId>net.logstash.logback</groupId>
<artifactId>logstash-logback-encoder</artifactId>
<version>${logstash-logback-encoder.version}</version>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.powermock</groupId>
<artifactId>powermock-module-junit4</artifactId>
<version>${powermock.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.powermock</groupId>
<artifactId>powermock-api-mockito</artifactId>
<version>${powermock.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.springframework.security</groupId>
<artifactId>spring-security-test</artifactId>
<version>${spring-security-test.version}</version>
<scope>test</scope>
</dependency>
</dependencies>
Run Code Online (Sandbox Code Playgroud)
声纳Maven的插件:
<plugin>
<groupId>org.codehaus.mojo</groupId> …Run Code Online (Sandbox Code Playgroud) 我之前在这个SO中提到过有关IE6/7(以及某些版本的Opera)的有趣行为,document.getElementById可以找到一个name属性已定义但不id属性的元素,这样
function f() {
document.getElementById("a1").value = ...;
}
...
<input name="a1" ...></input>
Run Code Online (Sandbox Code Playgroud)
实际上适用于这些版本.
通过网络搜索我发现了Chris Bloom的这个错误报告,其中名为Milo van der Leij的用户指出了以下内容(正如他在此w3c规范中所提到的):
在他们的辩护中:"id和name属性共享相同的名称空间."
id和name属性共享同一名称空间是什么意思?为什么这个条件足以让IE6/7/Opera在他们的JS引擎中实现这种行为?
有没有类似的子程序DBMS_METADATA.GET_DDL可以实际导出表数据作为INSERT语句?
例如,using DBMS_METADATA.GET_DDL('TABLE', 'MYTABLE', 'MYOWNER')将导出CREATE TABLEMYOWNER.MYTABLE 的脚本.从MYOWNER.MYTABLE生成所有数据作为INSERT语句?
我知道,例如TOAD Oracle或SQL Developer可以INSERT非常快速地导出语句,但我需要一种更加编程的方式来实现它.此外,我无法在我正在工作的数据库中创建任何过程或函数.
谢谢.
java ×3
maven ×2
12factor ×1
database ×1
docker ×1
dockerfile ×1
dom ×1
environment ×1
fluentd ×1
html ×1
immutability ×1
insert ×1
jacoco ×1
javascript ×1
linux-mint ×1
logging ×1
methods ×1
module ×1
oracle ×1
package ×1
quirks-mode ×1
ruby ×1
scala ×1
scala-2.8 ×1
security ×1
sonarqube ×1
spring ×1
spring-mvc ×1
traits ×1