我使用了 org.reflections (最新):
new Reflections("my.package").getSubTypesOf(MyService.class);
Run Code Online (Sandbox Code Playgroud)
它在 IntelliJ 中运行良好,并返回MyService.class.
但在 docker 容器中运行时,它返回一个空的Set.
(其他任何东西都可以在 docker-container 中正常运行)
有任何想法吗?蒂亚!
由于业务需求,我需要从球衣迁移到spring-mvc / rest ...
我正在寻找在弹簧MVC的东西,相当于新泽西州的ContainerRequestFilter,ContainerResponseFilter。
有任何想法吗?
我有以下 POJO:
public class Order {
private String orderCode;
// And many more ... getters and setter
}
Run Code Online (Sandbox Code Playgroud)
以及以下 REST 资源:
@Path("/customers/{customercode}/orders")
public class OrderResource {
@POST
@Consumes(MediaType.APPLICATION_JSON)
public Response create(@PathParam("customercode") String customerCode, Order order) {
// ...
}
// ...
}
Run Code Online (Sandbox Code Playgroud)
现在一些客户端将一个Order对象作为 JSON发送到这个 URL。该customerCode参数获取设置为预期值,但order参数是null,虽然这里是一个有效的JSON体的请求。(我可以在ContainerRequestContext对象中看到它。)
Jersey 的日志没有说明任何问题(即使在调试模式下)。
有任何想法吗?蒂亚!(我正在与 Jackson 一起使用 Jersey 2)
我正在使用Jersey(2.23.1)jersey-media-json-jackson.但这与杰克逊2.5.4有关.但我需要使用Jackson 2.6.0(或更新的版本).
我怎样才能做到这一点?
我试着在我的pom.xml中设置它:
<dependency>
<groupId>com.fasterxml.jackson.module</groupId>
<artifactId>jackson-module-jsonSchema</artifactId>
<version>2.6.0</version>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-annotations</artifactId>
<version>2.6.0</version>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.jaxrs</groupId>
<artifactId>jackson-jaxrs-xml-provider</artifactId>
<version>2.6.0</version>
</dependency>
Run Code Online (Sandbox Code Playgroud)
然后使用jackson 2.6.0.(我也试过新版本.)
但我的休息应用程序抛出各种NoSuchMethodError或ClassNotFoundExceptions类似:
org.glassfish.jersey.server.ContainerException: java.lang.NoSuchMethodError: com.fasterxml.jackson.jaxrs.cfg.EndpointConfigBase.<init>(Lcom/fasterxml/jackson/databind/cfg/MapperConfig;)
Run Code Online (Sandbox Code Playgroud)
有没有办法使用Jersey 2.23.1和Jackson 2.6.0或更新版本?TIA!
更新1:
这是一个完整的堆栈跟踪:
javax.servlet.ServletException: org.glassfish.jersey.server.ContainerException: java.lang.NoSuchMethodError: com.fasterxml.jackson.jaxrs.cfg.EndpointConfigBase.<init>(Lcom/fasterxml/jackson/databind/cfg/MapperConfig;)V
at org.glassfish.jersey.servlet.WebComponent.serviceImpl(WebComponent.java:489)
at org.glassfish.jersey.servlet.WebComponent.service(WebComponent.java:427)
at org.glassfish.jersey.servlet.ServletContainer.service(ServletContainer.java:388)
at org.glassfish.jersey.servlet.ServletContainer.service(ServletContainer.java:341)
at org.glassfish.jersey.servlet.ServletContainer.service(ServletContainer.java:228)
at org.eclipse.jetty.servlet.ServletHolder.handle(ServletHolder.java:812)
at org.eclipse.jetty.servlet.ServletHandler.doHandle(ServletHandler.java:587)
at org.eclipse.jetty.server.handler.ScopedHandler.handle(ScopedHandler.java:143)
at org.eclipse.jetty.security.SecurityHandler.handle(SecurityHandler.java:577)
at org.eclipse.jetty.server.session.SessionHandler.doHandle(SessionHandler.java:223)
at org.eclipse.jetty.server.handler.ContextHandler.doHandle(ContextHandler.java:1127)
at org.eclipse.jetty.servlet.ServletHandler.doScope(ServletHandler.java:515)
at org.eclipse.jetty.server.session.SessionHandler.doScope(SessionHandler.java:185)
at org.eclipse.jetty.server.handler.ContextHandler.doScope(ContextHandler.java:1061)
at org.eclipse.jetty.server.handler.ScopedHandler.handle(ScopedHandler.java:141)
at org.eclipse.jetty.server.handler.HandlerWrapper.handle(HandlerWrapper.java:97)
at org.eclipse.jetty.server.Server.handle(Server.java:499)
at org.eclipse.jetty.server.HttpChannel.handle(HttpChannel.java:311)
at org.eclipse.jetty.server.HttpConnection.onFillable(HttpConnection.java:257)
at org.eclipse.jetty.io.AbstractConnection$2.run(AbstractConnection.java:544) …Run Code Online (Sandbox Code Playgroud) 我有两个相同大小的 png 图像(A 和 B),第二个(B)是部分透明的。
如果我使用代码将图像 B 粘贴到图像 A 中
base.paste(overlay, mask=overlay)
Run Code Online (Sandbox Code Playgroud)
我得到了它们的近乎完美的组合。
但我想在将图像 B 粘贴到图像 A 之前使其变亮。我尝试使用像 Image.new("L", size, 80) 这样的蒙版,我可以用它使图像 (B) 变亮,但它也会使图像变暗( A) 并且不得修改。
在命令行上,我可以像这样使用 ImageMagick 做我想做的事:
composite -dissolve 40 overlay.png base.png result.png
Run Code Online (Sandbox Code Playgroud)
这正是我所需要的,但是我如何用 python 做到这一点。
使用Spring我需要某种环境(dev | test | prod)特定属性.
我只有一个配置文件(myapp.properties),由于某些原因,我不能有多个配置文件(即使spring可以处理多个).
所以我需要添加带有前缀的属性
dev.db.user=foo
prod.db.user=foo
Run Code Online (Sandbox Code Playgroud)
并告诉应用程序使用哪个前缀(环境)与VM-argument -Denv-target或类似的东西.
我有一些实体,其中一些字段用hibernate-validator注释注释,如:
@Entity
public class MyEntity {
@Pattern(regexp = "[A-Z,0-9]{3,}")
@Column
private String key;
@Range(min = 1, max = 999)
@Column
private Integer year;
// [...]
}
Run Code Online (Sandbox Code Playgroud)
有没有办法在wicket组件(如表单)中使用thoose验证器注释?
我有这个类,想要记录其余的请求:
public class RequestFilter implements ContainerRequestFilter {
private static final Logger LOG = LoggerFactory.getLogger(RequestFilter.class);
@Override
public void filter(ContainerRequestContext requestContext) throws IOException {
LOG.info("REST-Request from '{}' for '{}'", "XXX", requestContext.getUriInfo().getPath());
// ... and do some auth stuff (not relevant for this question)
}
}
Run Code Online (Sandbox Code Playgroud)
如何获取请求的远程IP?TIA!
我有以下hibernate实体:
@Entity
public class Customer {
@OneToMany(mappedBy = "customer", cascade = CascadeType.ALL, fetch = FetchType.EAGER)
private List<Address> addresses = new ArrayList<>();
@OneToMany(mappedBy = "customer", cascade = CascadeType.ALL, fetch = FetchType.EAGER)
private List<Contact> contacts = new ArrayList<>();
@OneToMany(mappedBy = "customer", cascade = CascadeType.ALL, fetch = FetchType.EAGER)
private List<Name> names = new ArrayList<>();
// Many more, including a primary key
}
Run Code Online (Sandbox Code Playgroud)
启动应用程序,我得到以下异常:
org.hibernate.loader.MultipleBagFetchException: cannot simultaneously fetch multiple bags
Run Code Online (Sandbox Code Playgroud)
如果我删除一个仲裁OneToMany协会,或者如果我添加一个@Fetch(value = FetchMode.JOIN)仲裁OneToMany协会,一切正常.
这是一个hibernate错误,一个hibernate限制,还是我的实体有什么问题?TIA!
我有一个类似的课程
public class Person {
public Person(String firstName) {...}
public String getFirstname() {...}
// ... some other fields
}
Run Code Online (Sandbox Code Playgroud)
以及这些类的对象列表:
List<Person > objList = new ArrayList<>();
objList.add(new Person("Peter"));
objList.add(new Person("James"));
objList.add(new Person("Bart"));
Run Code Online (Sandbox Code Playgroud)
现在我需要一个以逗号分隔的列表,列出这个对象列表的第一个名字,比如"Peter,James,Bart".
我怎么能用lambdas和Java 8流做到这一点?TIA!
java ×8
rest ×4
jersey ×3
spring ×3
hibernate ×2
jersey-2.0 ×2
json ×2
docker ×1
imaging ×1
jackson ×1
java-8 ×1
jax-rs ×1
lambda ×1
properties ×1
python ×1
reflections ×1
spring-boot ×1
spring-mvc ×1
transparency ×1
wicket ×1