小编kry*_*ger的帖子

如何在filtermapping中排除网址

web.xml中

<filter>
    <filter-name>SessionCheckFilter</filter-name>
    <filter-class>filter.SessionCheckFilter</filter-class>
</filter>
<filter-mapping>
    <filter-name>SessionCheckFilter</filter-name>
    <url-pattern>/faces/app/admin/*</url-pattern>
</filter-mapping>
Run Code Online (Sandbox Code Playgroud)

我试图排除/faces/app/admin/index.xhtml唯一的,有没有办法做到这一点?

如果在web.xml中没有排除url patterin,也许我可以操纵该doFilter()方法来排除url?

java web.xml url-pattern servlet-filters

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

BeanUtils copyProperties API忽略null和特定属性

Spring BeanUtils.copyProperties()提供了在复制bean时忽略特定属性的选项:

public static void copyProperties(Object source,
                 Object target,
                 String[] ignoreProperties) throws BeansException
Run Code Online (Sandbox Code Playgroud)

Apache Commons BeanUtils是否提供类似的功能?

使用Spring时也可以忽略空值BeanUtils.copyProperties(),我在Commons BeanUtils中看到这个功能:

Date defaultValue = null;
DateConverter converter = new DateConverter(defaultValue);
ConvertUtils.register(converter, Date.class);
Run Code Online (Sandbox Code Playgroud)

我可以用Spring的BeanUtils实现同样的目标吗?

java mapping spring apache-commons-beanutils

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

JMeter,JUnit和Spring Java配置

是否可以使用JUnit插件/采样器和Spring Java配置运行JMeter?当我尝试这样做时,没有创建Spring自动装配的bean,虽然测试用例运行,因为尚未创建bean,我得到空指针异常.

我正在使用Spring注释 @SpringJUnit4ClassRunner@ContextConfiguration配置JUnit测试(可以工作).目标是能够编写可以使用JMeter测量性能的JUnit测试用例.

junit spring jmeter autowired

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

如何使用弹簧数据jpa的投影和规格?

我无法一起使用Spring Data JPA投影和规范.我有以下设置:

实体:

@Entity
public class Country {

    @Id
    @GeneratedValue(strategy = GenerationType.AUTO)
    private Long id;

    @Column(name = "NAME", nullable = false)
    private String name;

    @Column(name = "CODE", nullable = false)
    private String code;

    ---getters & setters---

}
Run Code Online (Sandbox Code Playgroud)

投影界面:

public interface CountryProjection {
    String getName();
}
Run Code Online (Sandbox Code Playgroud)

国家规格:

public class CountrySpecification {
    public static Specification<Country> predicateName(final String name) {
        return new Specification<Country>() {
            @Override
            public Predicate toPredicate(Root<Country> eventRoot, CriteriaQuery<?> criteriaQuery, CriteriaBuilder criteriaBuilder) {
                return criteriaBuilder.equal(eventRoot.get(Country_.name), name);
            }
        };
    }
}
Run Code Online (Sandbox Code Playgroud)

库: …

hibernate jpql spring-data-jpa spring-boot

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

为什么"mvn verify"没有运行我的集成测试?

我有一个多模块项目,我在root pom中定义了failafe,如下所示:

<plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-failsafe-plugin</artifactId>
    <version>2.19</version>
    <configuration>
        <includes>
            <include>**/*IntegrationTest.java</include>
            <include>**/*JourneyTest.java</include>
            <include>**/*CucumberFeatureTest.java</include>
        </includes>
    </configuration>
    <executions>
        <execution>
            <goals>
                <goal>integration-test</goal>
                <goal>verify</goal>
            </goals>
        </execution>
    </executions>
</plugin>
<plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-surefire-plugin</artifactId>
    <version>2.19</version>
    <configuration>
        <excludes>
            <exclude>**/*IntegrationTest.java</exclude>
            <exclude>**/*JourneyTest.java</exclude>
            <exclude>**/*CucumberFeatureTest.java</exclude>
        </excludes>
    </configuration>
</plugin>
Run Code Online (Sandbox Code Playgroud)

我的其他poms中的其他任何地方都没有定义Failsafe.如果我运行mvn verify,它会跳过集成测试(它运行单元测试).但如果我运行mvn test-compile failsafe:integration-test,它会运行集成测试.

我假设故障安全应该在这两种情况下运行.那么为什么我输入时它不会运行mvn verify

更新:刚刚注意到这是围绕这些标签:

<build>
    <pluginManagement> <!-- oops -->
        <plugins>
            <plugin>
Run Code Online (Sandbox Code Playgroud)

我觉得这解释了原因,但我不知道为什么单元测试仍然运行像你期待与mvn verifymvn test.为什么在这方面,surefire与故障保护的工作方式不同?

java maven maven-failsafe-plugin

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

Websockets和负载平衡

Spring和Java EE对websockets提供了很好的支持.例如在Spring中,您可以:

@Configuration
@EnableWebSocket
public class WebSocketConfig implements WebSocketConfigurer {

    @Override
    public void registerWebSocketHandlers(WebSocketHandlerRegistry registry) {
        registry.addHandler(new MyHandler(), "/myHandler")
            .addInterceptors(new HttpSessionHandshakeInterceptor());
    }

}
Run Code Online (Sandbox Code Playgroud)

通过MyHandler类,您可以发送和侦听HTML5 websocket的消息.

var webSocket = 
      new WebSocket('ws://localhost:8080/myHandler');
 webSocket.onmessage = function(event) {
      onMessage(event)
    };
Run Code Online (Sandbox Code Playgroud)

问题是如果您在负载均衡器后面运行多个服务器.服务器A的客户端不会收到服务器B上的事件通知.

Spring中使用带有Stomp协议的消息代理解决了这个问题(http://assets.spring.io/wp/WebSocketBlogPost.html)

由于使用处理程序和"本机"html5 websockets对我来说更容易,然后是Stomp方式,我的问题是:

  1. 没有Stomp协议使用消息代理是否可行?
  2. 还有其他选择可以克服负载平衡问题吗?

javascript java html5 spring websocket

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

Jacoco - 零覆盖率

我正在尝试将jacoco集成到我们的ant构建中,并使用一个简单的测试项目对其进行评估.

编译和其他输出看起来很有希望,但是当我查看覆盖范围时,它总是为零.

package alg;

public class SpecialAlgorithm {
    public SpecialAlgorithm() {}

    public int uncoveredMethod(int i) {
        return i * i;
    }

    public int sum(int i, int j) {
        return i + j;
    }   
}
Run Code Online (Sandbox Code Playgroud)

测试用例:

package alg;

import static org.junit.Assert.assertEquals;
import org.junit.Test;
import alg.SpecialAlgorithm;

public class SpecialAlgorithmTest {
    @Test
    public void testSum() {
        SpecialAlgorithm alg = new SpecialAlgorithm();
        int sum = alg.sum(1, 2);
        assertEquals(3, sum);
    }
}
Run Code Online (Sandbox Code Playgroud)

Ant脚本:

<project xmlns:jacoco="antlib:org.jacoco.ant" name="Code Coverage with JaCoCo"
    default="rebuild">
    <property name="src.dir" location="../java" />
    <property …
Run Code Online (Sandbox Code Playgroud)

java jacoco

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

我应该如何在Spring数据存储库上使用@Cacheable

例如,在使用时,MongoRepository有一些方法我想标记@Cacheableinsert(entity)findOne(id).既然它是一个Spring存储库而不是我的存储库,我应该如何使用@Cacheable这些方法呢?

java spring-data spring-boot

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

使用Spring Boot,如何查看Zuul的调试信息?

我想在我的Spring Boot项目中使用Zuul.

application.properties

server.context-path=/${spring.application.name}
zuul.routes.engine.path=/api/engine/**
zuul.routes.engine.url=${engine.url}
Run Code Online (Sandbox Code Playgroud)

GET请求正在运行; 但是,Zuul没有转发我的POST请求.我没有看到任何调试输出为无论是GET还是POST在这里列出:如何使用.

如何DEBUG为Zuul 启用日志记录模式?

spring spring-boot spring-cloud netflix-zuul

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

如何在JUnit中比较两个double列表

在JUnit 4测试中,我有一个方法getValues()返回一个List<Double>我想要与引用列表进行比较的对象.到目前为止,我发现的最佳解决方案是使用org.hamcrest.collection.IsArray.hasItemsorg.hamcrest.Matchers.closeTo喜欢这样:

assertThat(getValues(), hasItems(closeTo(0.2, EPSILON), closeTo(0.3, EPSILON)));
Run Code Online (Sandbox Code Playgroud)

这适用于仅返回少量值的测试.但是如果测试返回更多值,这绝对不是最好的方法.

我也尝试了以下代码.要编译的代码需要向下转换为Matcherbefore hasItems:

List<Matcher<Double>> doubleMatcherList = new ArrayList<Matcher<Double>>();
doubleMatcherList.add(closeTo(0.2, EPSILON));
doubleMatcherList.add(closeTo(0.3, EPSILON));
assertThat(getValues(), (Matcher) hasItems(doubleMatcherList));
Run Code Online (Sandbox Code Playgroud)

比较失败,我不明白为什么:

java.lang.AssertionError:Expected :(一个包含<[数字值<1.0E-6> <0.2>的数字​​,<1.0> -0> <0.3>的数值>]>的集合得到:<[ 0.2,0.30000000000000004]>

是否有更好的方法来比较两个大型双打名单?这里的困难是需要数值公差来验证结果getValues()是否等于我的参考列表.对于任何对象列表,这种比较似乎都很容易,但对于列表却没有Double.

java junit hamcrest

9
推荐指数
2
解决办法
2085
查看次数