小编Hen*_*nri的帖子

Jackson:“(尽管至少存在一个 Creator):没有用于反序列化的字符串参数构造函数/工厂方法”

尽管这个问题听起来很简单,但我在一个非常简单的 bean 上也遇到了这个异常:

@Data
public class Foo {
  private List<Error> errors;

  @Data
  public static class Error {
    private int code;
    private String message;
  }
}
Run Code Online (Sandbox Code Playgroud)

JSON:

{
  "errors": [
    "message": "bla bla bla"
  ]
}
Run Code Online (Sandbox Code Playgroud)

例外情况:com.fasterxml.jackson.databind.exc.MismatchedInputException: Cannot construct instance of "org.example.app.Foo$Error" (although at least one Creator exists): no String-argument constructor/factory method to deserialize from String value ('message')

该应用程序:

@SpringBootApplication
public class Application {
  public static void main(String[] args) throws Exception {
    ApplicationContext context = SpringApplication.run(Application.class, args);
    ObjectMapper objectMapper = …
Run Code Online (Sandbox Code Playgroud)

java spring json lombok deserialization

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

Visual Studio 2012上的静态ZLIB(1.2.8)链接

对于上帝的爱,我不能静态链接ZLIB库.我一直在苦苦挣扎几个小时但没有成功.好吧,我已经按照本教程成功编译了32位的zlibstat.lib和zlibwapi.lib.设置我的项目以将ZLIB文件夹与库(链接器>常规>附加库目录)一起使用并将zlibwapi.lib(仅)设置为依赖项(链接器>输入>附加依赖项)后,我让它工作,但是,是一个动态链接(我需要使用ZLIB dll分发我的应用程序).我通常在Debug上使用动态链接,在Release上使用static.

假设"stat"后缀,我试图寻找zlibstat.lib到底是什么以及它用于什么,如果不是静态链接.

有没有被添加到我的项目中的预处理程序,像ZLIB_STATIC或东西,使用zlib的静态链接还是应该我从来没有移除了zlibstat项目ZLIB_WINAPI,就像上面的链接告诉我做什么?静态链接ZLIB是不可能的(那么,zlibstat.lib是什么?)?

我很丢失.任何帮助是极大的赞赏.

编辑(额外信息):

错误:

error LNK2001: unresolved external symbol _inflateInit_@12
error LNK2001: unresolved external symbol _inflate@8
error LNK2001: unresolved external symbol _inflateEnd@4
Run Code Online (Sandbox Code Playgroud)

链接:

与我添加zlibwapi.lib作为依赖项的动态链接(有效)不同,对于我想要实现的静态链接,我添加了zlibstat.lib作为依赖项!没有添加其他库!

这个问题可能看起来像这样(有点).

zlib static-linking visual-studio-2012

7
推荐指数
1
解决办法
6056
查看次数

如何有效删除更新的 HashSet 项

给定以下代码片段,我们如何有效地删除先前已更新/更改的元素?

public static class Foo {
    @Override
    public int hashCode() {
        return new Random().nextInt();
    }
}

public static void main(String[] args) {
    Set<Foo> set = new HashSet<>();

    set.add(new Foo());
    set.removeIf(f -> true); // Returns true, but no deletion occurs

    assert set.size() == 0; // Fails as set still contains it's single item
}
Run Code Online (Sandbox Code Playgroud)

注意:上面的代码片段旨在模拟Foo下次调用时的不同情况Object::hashCode(在 Set::remove 和 Set::removeIf 上)。

编辑:

对于那些不理解“随机哈希”部分的人,这里是对上述问题的不同看法:

public static class Bar {

    public String firstName;
    public String lastName;

    public Bar() {
        this(null, null); …
Run Code Online (Sandbox Code Playgroud)

java hashset

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

查找给定数字所属的数字(范围)集,而不使用循环

我很困惑,根据以下标准决定使用哪种算法或哪种算法来查找对象:有2个类:'TileSets'和'Tile'.TileSet有2个int属性:firstTileId和lastTileId,而Tile有一个int属性:id,如下所示:

struct TileSet { int firstTileId, lastTileId; } 

struct Tile { int id; }
Run Code Online (Sandbox Code Playgroud)

该应用程序应该有不超过10个TileSet(通常为3-5)和10.000+ Tiles.速度对于确定具有给定id的TileSet哪个TileSet属于哪个非常重要.将tileset添加到向量后,第一个和最后一个id属性不会更改,并且它们不会相互重叠,例如:{{1,25},{26,125},{126,781},{ 782,789} ...}.我们可以看到,瓷砖范围内没有任何孔.瓷砖矢量不是订购也不是.我目前的实现(伪短代码的种类)是:

Vector t = 10.000+ tiles
Vector ts = tilesets with a size of a number of a power of 2 number bigger than 6, at least
for tileIndex = 0; tileIndex < t.size; tileIndex++, do:
   for tilesetIndex = 0; tilesetIndex < ts.size; tilesetIndex++, do:
      if (ts[tilesetIndex].firstTileId >= t[tileIndex].id && t[tileIndex].id <= ts[tilesetIndex].lastTileId) 
         // tile t[tileIndex] belongs to the tileset ts[tilesetIndex]! Done!
Run Code Online (Sandbox Code Playgroud)

我可以在这种情况下使用什么样的算法?这有什么公式吗?

c++ algorithm hash

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

docker-compose 文件无法构建镜像

我有一个这样的项目结构:

root (folder)
--- foo (folder)
------ target (folder)
------ Dockerfile (file)
--- bar (folder)
------ target (folder)
------ Dockerfile (file)
--- docker-compose.yml (file)
Run Code Online (Sandbox Code Playgroud)

这是 docker-compose 文件:

version: "3.9"
services:
  foo-service:
    image: foo-image:latest
    container_name: foo-container
    build:
      context: .
      dockerfile: foo/Dockerfile
  bar-service:
    image: bar-image:latest
    container_name: bar-container
    build:
      context: .
      dockerfile: bar/Dockerfile
Run Code Online (Sandbox Code Playgroud)

Dockerfile 两者都相同,如下所示:

FROM openjdk:8-jdk-alpine
COPY target/*.jar app.jar
CMD ["java", "-jar", "/app.jar"]
Run Code Online (Sandbox Code Playgroud)

当我尝试运行时docker-compose up,它在步骤 2(复制步骤)上失败:“未指定源文件”。当docker build .单独运行每个时,它可以工作。

我该如何解决这个问题?

docker dockerfile docker-compose

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

继承和智能指针(std :: shared_ptr)

有很多事情需要说.首先,我想知道下面的方法是否被认为是设计模式甚至是一种常用技术(这就是为什么我没有提供有关标题的更多信息).如果是这样,那么名字是什么?无论如何,这是我想要实现的缩小版本.由于我需要使用复制,我发现使用std :: shared_ptr是最好避免被释放(删除)的指针.

class Foo
{
public:
    Foo() : ptr(nullptr) {}
    Foo(const Foo& foo) : ptr(foo.ptr) {}
    virtual ~Foo() = default;

    void whatever() {
        if (ptr)
            ptr->whateverHandler();
    }

    void reset() {
        ptr.reset();
    }

    void resetBar() {
        ptr.reset(new Bar);
    }

    // Other resets here...

protected:
    Foo(Foo* foo) : ptr(foo) {}

private:
    // Every child class should override this
    virtual void whateverHandler() {
        throw "whateverHandler cant be called within base class";
    }

protected:
    std::shared_ptr<Foo> ptr;
};

class Bar : public Foo
{ …
Run Code Online (Sandbox Code Playgroud)

c++ inheritance virtual-functions smart-pointers shared-ptr

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

启动Spring应用程序时出错:bean的初始化失败; 嵌套异常是AbstractMethodError

我有一个使用Spring MVC,Spring Security和Spring Data的Spring应用程序.一切都过去完美无缺,直到我将Spring Data的版本更新1.9.0.RELEASE2.x.

这是无法创建的存储库bean(BeanCreationException):

@Repository // Enables exception translation
public interface UsuarioRepository extends CrudRepository<Usuario, Long> {

    @Query("SELECT u FROM Usuario u WHERE LOWER(u.login) = LOWER(:login)")
    Usuario findByLogin(@Param("login") String login);

    @Query(value = "SELECT * FROM Usuario WHERE fl_ativo = true", nativeQuery = true)
    Iterable<Usuario> findAllActives();

}
Run Code Online (Sandbox Code Playgroud)

这是pom.xml(Maven):

<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">
    <!-- Artifact details -->
    <modelVersion>4.0.0</modelVersion>
    <groupId>br.com.nooder</groupId>
    <artifactId>portal-jstl</artifactId>
    <version>0.0.1-SNAPSHOT</version>
    <packaging>war</packaging>

    <!-- Properties -->
    <properties>
        <project.build.version.log4j>2.8.2</project.build.version.log4j>
        <project.build.version.junit>4.12</project.build.version.junit>
        <project.build.version.slf4j>1.7.25</project.build.version.slf4j>
        <project.build.version.hibernate>5.2.12.Final</project.build.version.hibernate>
        <project.build.version.spring>4.3.8.RELEASE</project.build.version.spring>
        <project.build.version.spring.data>2.0.2.RELEASE</project.build.version.spring.data>
        <project.build.version.spring.security>4.2.2.RELEASE</project.build.version.spring.security>
    </properties> …
Run Code Online (Sandbox Code Playgroud)

java spring maven spring-data spring-data-jpa

0
推荐指数
1
解决办法
3920
查看次数