小编jb6*_*b62的帖子

Spring Boot app:没有拿起application.properties?

我有一个我在这里的春季启动应用程序:https: //github.com/christophstrobl/spring-data-solr-showcase/tree/4b3bbf945b182855003d5ba63a60990972a9de72

它编译并正常工作: mvn spring-boot:run

但是,当我在Spring Tools Suite中单击"作为Spring Boot应用程序运行"时,出现无法找到的错误 ${solr.host},指出 application.properties文件中设置的内容.

org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'productServiceImpl': Injection of autowired dependencies failed; nested exception is org.springframework.beans.factory.BeanCreationException: Could not autowire method: public void org.springframework.data.solr.showcase.product.ProductServiceImpl.setProductRepository(org.springframework.data.solr.showcase.product.ProductRepository); nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'productRepository': Initialization of bean failed; nested exception is java.lang.IllegalArgumentException: Could not resolve placeholder 'solr.host' in string value "${solr.host}"
Run Code Online (Sandbox Code Playgroud)

我的applications.properties文件如下所示:

# SPRING MVC
spring.view.suffix=.jsp
spring.view.prefix=/WEB-INF/views/

# SOLR
solr.host=http://192.168.56.11:8983/solr
Run Code Online (Sandbox Code Playgroud)

相关类看起来像这样(唯一使用$ solr.host变量的地方).此外,如果我直接解决SOLR服务器的IP(如在注释代码中),应用程序就可以正常启动.

* Copyright 2012 - 2014 …
Run Code Online (Sandbox Code Playgroud)

java spring solr spring-mvc maven

18
推荐指数
7
解决办法
6万
查看次数

org.mockito.exceptions.misusing.InvalidUseOfMatchersException' 异常

我在 Stack Overflow 上查看了一些相关问题,但没有找到匹配的问题。

我正在使用 Mockito 并尝试为具有以下签名的方法创建自定义参数匹配器。

public ClusterViewMember getPersonWithTreeInfo(Gid clusterGid, Gid memberGid, boolean retBlob) throws Exception
Run Code Online (Sandbox Code Playgroud)

代码失败并显示“InvalidUseOfMatchersException”整个异常消息是:

Method threw 'org.mockito.exceptions.misusing.InvalidUseOfMatchersException' exception. Cannot evaluate com.xxx.yyy.services.pm3cache.provider.PmCacheProvider$$EnhancerByMockitoWithCGLIB$$c81cff41.toString()
Run Code Online (Sandbox Code Playgroud)

该代码行因空指针异常而失败。我通过在调试模式下单步执行来找到 Mockito 异常。单独的代码行如下。

when(pmCacheProvider.getPersonWithTreeInfo(any(), any(), any())).thenReturn(new ClusterViewMember());
Run Code Online (Sandbox Code Playgroud)

最后 - 整个测试方法如下。

2 注意事项:

  1. 执行不会越过“when”行——这就是错误发生的地方。

  2. 我正在调用的 Foo (提供程序)中的方法最终会调用我正在为其编写自定义匹配器的方法。换句话说,“getMemberData()”最终会调用“getPersonWIthTreeInfo()”

@Test
public void testGetMemberData()
      throws Exception {

    Gid memberGid = new Gid("1:2");
    Gid clusterGid = new Gid("3:4");
    boolean retBlob = true;

    Pm3CacheDataProviderMetricsTestImpl metrics = new Pm3CacheDataProviderMetricsTestImpl();
    PmCacheProvider pmCacheProvider = mock(PmCacheProvider.class);

    when(pmCacheProvider.getPersonWithTreeInfo(any(), any(), any())).thenReturn(new ClusterViewMember());

    Foo provider = new Foo(pmCacheProvider,metrics); …
Run Code Online (Sandbox Code Playgroud)

java testing unit-testing mockito

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

从方法调用返回时模拟和处理 Map.Entry

摘要:我对从方法调用返回时如何处理单个“Map.Entry”感到困惑。在我的具体情况下,我需要模拟这个(目前使用mockito),但我的问题是如何将“Map.Entry”作为一个单元处理,而不是模拟它......两者的帮助将是巨大的赞赏。

===========================

我有一个像下面这样的方法。我需要创建一个匹配的实体(我假设是一个 Map.Entry),以便在调用该方法时返回模拟。我不知道如何创建单个 Map.Entry。我已经跟踪调用一直追溯到对数据库的 sql 调用,但只能找到将返回的对象转换为 Map.Entry 的点。

没有说明如何构建这样的东西。我需要有关如何构建可由模拟返回的单个“Map.Entry”的帮助。

 public Map.Entry<Date,Boolean> getLastModified(SomeClass someClass)
    throws Exception
    {
        return clusterViewDataProvider.getClusterModified(someClass);
    }
Run Code Online (Sandbox Code Playgroud)

这是一行将为我创建模拟对象的行。为了简单起见,假设上面的方法位于“Foo”类中。

Foo foo = mock(Foo.class);
Run Code Online (Sandbox Code Playgroud)

然后我需要这样的东西来说明当调用该方法(作为模拟)时,它应该返回我需要构建的“Map.Entry”。

when(foo.getLastModifiedGid(any())).thenReturn(the Map.Entry I don't know how to make yet);
Run Code Online (Sandbox Code Playgroud)

最后,我需要断言返回的 Map.Entry 的一些可测试内容。我可以检查断言中的键和值 - 没有比这更奇特的了 - 再次,我不确定如何将其作为单个 Map.Entry 访问...

assertTrue(The Key == SomeDate)
assertTrue(The Value == True)
Run Code Online (Sandbox Code Playgroud)

如果我有任何不清楚的地方,请发表评论,我会澄清。谢谢。

java collections unit-testing

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

标签 统计

java ×3

unit-testing ×2

collections ×1

maven ×1

mockito ×1

solr ×1

spring ×1

spring-mvc ×1

testing ×1