小编ykt*_*too的帖子

Logback - 如何让每个记录器记录到单独的日志文件中?

我的应用程序有很多EJB.当前定制的Logger实现创建了一个这样的记录器;

private static Logger logger = Logger.getInstance("SERVICE_NAME");

,日志记录将进入文件;

(路径)/SERVICE_NAME/SERVICE_NAME.log

我想用logback复制这种行为,但是在logback.xml配置中抓住'logger'名称时遇到了麻烦.它可以在log encoder.pattern中看到,即"%d%-5level%logger {35} - %msg%n".

有什么想法我怎么能把它变成属性/变量然后在元素中使用它?

logback

6
推荐指数
1
解决办法
3685
查看次数

Hibernate 5无法正确处理LocalDate

我们正在将我们的Hibernate(5.0.2)代码迁移到Java 8,它还涉及从转换java.util.Datejava.time.LocalDate(以解决与Java 7中的日期处理相关的问题).我遇到的一个问题是Hibernate如何处理我们用作"零日期"的特殊值,即0001-01-01.

该属性声明如下:

@NotNull
@Column(name = "START_DATE", nullable = false)
private LocalDate startDate;
Run Code Online (Sandbox Code Playgroud)

该值存储在数据库中0001-01-01,但是当它被Hibernate加载时,它突然转向0000-12-29.我假设发生这种情况是因为Hibernate默认使用格里高利历,并且因为这个日期是在它引入之前,所以使用了一些转换.

有没有办法配置Hibernate来禁用这种行为(除了实现一个特殊的属性编写器)?

java datetime hibernate java-8 hibernate-5.x

6
推荐指数
1
解决办法
1370
查看次数

滚动到 GtkListBox 中选定的行

我在这里有点没有主意。我想要一件非常简单的事情:能够GtkListBox以编程方式选择给定行,然后滚动列表框(包含在 aScrolledWindow和 a中Viewport)。

选择一行很简单(我的代码是 Go & gotk3,但这并不那么重要):

listBox.SelectRow(row)
Run Code Online (Sandbox Code Playgroud)

但事实证明,滚动到该行是一个真正的挑战。无论我尝试什么,我都失败了:

  • 我试图集中注意力,但没有任何帮助
  • 我尝试使用 找出该行的 Y 坐标gtk_widget_translate_coordinates(),但它对任何行返回 -1
  • 也许我可以找出列表框顶部和底部的哪一行,并使用它来滚动,ScrolledWindow但我不知道如何做到这一点。

更新:我已经尝试过这里建议的内容:Manually roll to a child in a Gtk.ScrolledWindow,但它不起作用,因为仍然没有发生滚动:

listbox.SelectRow(rowToSelect)
listbox.SetFocusVAdjustment(listbox.GetAdjustment())
if rowToSelect != nil {
    rowToSelect.GrabFocus()
}
Run Code Online (Sandbox Code Playgroud)

我也使用下面的代码对 的孩子进行了相同的尝试rowToSelect,但无济于事:

if c, err := rowToSelect.GetChild(); err == nil {
    c.GrabFocus()
}

Run Code Online (Sandbox Code Playgroud)

gtk go gtk3

6
推荐指数
1
解决办法
1213
查看次数

找出 Karma 测试期间哪个 Angular 组件发出错误

运行 Karma 测试时,我收到很多错误(实际上是警告),如下所示:

ERROR: 'NG0304: 'fa-icon' is not a known element:
1. If 'fa-icon' is an Angular component, then verify that it is part of this module.
2. If 'fa-icon' is a Web Component then add 'CUSTOM_ELEMENTS_SCHEMA' to the '@NgModule.schemas' of this component to suppress this message.'

Run Code Online (Sandbox Code Playgroud)

现在,一旦您知道哪个组件抱怨未知元素,这个问题就很容易解决。问题是应用程序有几十个这样的问题,而 Karma 的输出没有提供任何关于问题出现的线索。

如何找出导致错误的组件,而不需要有选择地针对每个组件运行测试?

karma-runner angular

6
推荐指数
1
解决办法
356
查看次数

测试期间 Spring MVC 控制器 JSON 日期序列化

我正在为 Spring MVC 4.2.x REST 控制器编写单元测试,并且对 Jackson (2.6.x) 序列化的日期有问题。运行应用程序时,日期 ( java.util.Date) 默认以默认格式序列化yyyy-MM-dd(无需额外配置),这就是我想要的。

然而,在测试期间,由于未知原因,日期被序列化为时间戳。

这是测试类的一些示例代码:

public class OrderControllerTest {

    @Mock
    private OrderService service;

    @InjectMocks
    private OrderController controller;

    private MockMvc mockMvc;

    private List<Order> orders = new ArrayList<>();

    @Before
    public void setup() {
        MockitoAnnotations.initMocks(this);
        mockMvc = MockMvcBuilders.standaloneSetup(controller).build();
        // Initialize dummy order list
        orders.add(...);
        orders.add(...);
        orders.add(...);
    }

    @Test
    public void list() throws Exception {
        // Stub the service find method
        when(service.find(asOfDate, null)).thenReturn(orders);

        // Run the controller and check the result
        MvcResult …
Run Code Online (Sandbox Code Playgroud)

json unit-testing spring-mvc mockito

5
推荐指数
0
解决办法
2266
查看次数

使用Maven,Protractor和Selenium WebDriver进行集成测试

我们开发了一个Web应用程序,它在后端使用Java,在Angular中使用UI,使用Maven作为构建系统.

我一直在尝试使用Protractor设置自动集成测试,并且在加载Googling/StackOverflowing之后仍然无法弄清楚如何实现端到端配置.

Node.js/NPM安装(失败)

我已经尝试使用frontend-maven-plugin来处理Node.js和NPM安装,但由于我们是在公司防火墙后面,所以似乎无法直接下载任何东西.它可以从我们的Artifactory下载Node但是在NPM下载时失败了(我不明白为什么它甚至下载它因为它是Node包的一部分).无论如何,我放弃了这个想法,并决定使用本地安装的Node.

启动Tomcat

启动/停止用于e2e测试的Tomcat实例可以很好地处理

        <plugin>
            <groupId>org.apache.tomcat.maven</groupId>
            <artifactId>tomcat7-maven-plugin</artifactId>
            <version>2.2</version>
            <configuration>
                <url>${tomcat.manager.url}</url>
                <path>/</path>
                <server>Tomcat</server>
            </configuration>
            <executions>
                <!-- Starting Tomcat -->
                <execution>
                    <id>start-tomcat</id>
                    <phase>pre-integration-test</phase>
                    <goals>
                        <goal>run</goal>
                    </goals>
                    <configuration>
                        <!-- Fork the process, otherwise the build will be blocked by the running Tomcat -->
                        <fork>true</fork>
                        <port>${tomcat.port}</port>
                        <systemProperties>
                            <!-- We want to use the 'e2e' profile for integration testing -->
                            <spring.profiles.active>e2e</spring.profiles.active>
                        </systemProperties>
                    </configuration>
                </execution>
                <!-- Stopping Tomcat -->
                <execution>
                    <id>stop-tomcat</id>
                    <phase>post-integration-test</phase>
                    <goals>
                        <goal>shutdown</goal>
                    </goals>
                </execution>
            </executions>
        </plugin>
Run Code Online (Sandbox Code Playgroud)

使用WebDriver(失败)

我设法启动WebDriver,但问题是它阻止了任何进一步的执行:

        <plugin>
            <groupId>org.codehaus.mojo</groupId> …
Run Code Online (Sandbox Code Playgroud)

selenium maven node.js angularjs protractor

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

Maven:在一个阶段运行两次插件,与另一个插件交错

对于我们的 end-2-end 测试,我们需要执行以下逻辑流程:

  1. 在数据库中创建和设置 e2e 模式(用户) ( pre-integration-test)
  2. 运行 Liquibase 以初始填充架构 ( pre-integration-test)
  3. 将特定于 e2e 的测试数据添加到数据库表 ( pre-integration-test)
  4. 启动 Tomcat ( pre-integration-test)
  5. integration-test使用 Protractor在 Tomcat ( ) 中运行 Web 应用程序
  6. 关闭 Tomcat ( post-integration-test)
  7. 清理数据库:删除架构 ( post-integration-test)

对于运行 SQLsql-maven-plugin使用,但是此流程不适合常规 POM 布局:

  • 在SQL插件有期间运行pre-integration-test两次,之前之后liquibase-maven-plugin
  • SQL 插件必须Tomcat 插件之前运行during pre-integration-test,但是它必须during之后运行post-integration-test,以便在 Tomcat 关闭后删除 DB 模式。

据我从Maven docs …

java tomcat liquibase maven sql-maven-plugin

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

Sprint引导数据JPA:没有类型为'java.util.Set <javax.persistence.EntityManager>'的限定bean

我无法开始使用spring-boot-starter-data-jpa.我按照本指南创建了一个简单的Spring Boot应用程序,但是使用了Hibernate和相关的配置.

的build.gradle:

dependencies {
    // Spring stuff
    compile 'org.springframework.boot:spring-boot-starter-data-jpa:1.5.1.RELEASE'
    compile 'org.springframework.data:spring-data-jpa'
    compile 'org.springframework:spring-webmvc'
    // Jackson
    compile 'com.fasterxml.jackson.core:jackson-databind:+'
    compile 'com.fasterxml.jackson.dataformat:jackson-dataformat-yaml:+'
    // Postgres
    compile 'org.postgresql:postgresql:+'
    // Hibernate
    compile 'org.hibernate:hibernate-core:5.2.8.Final'
}
Run Code Online (Sandbox Code Playgroud)

每当我尝试运行应用程序时,我最终会得到以下结果:

Error starting ApplicationContext. To display the auto-configuration report re-run your application with 'debug' enabled.
2017-02-24 16:20:27.710 ERROR 1070 --- [           main] o.s.boot.SpringApplication               : Application startup failed

org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'jpaContext': Unsatisfied dependency expressed through constructor parameter 0; nested exception is org.springframework.beans.factory.NoSuchBeanDefinitionException: No qualifying …
Run Code Online (Sandbox Code Playgroud)

java spring hibernate jpa spring-boot

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