小编Gio*_*ato的帖子

在 POM 中使用 --enable-preview 执行 Maven 插件

我有一个使用 JDK 12 预览功能的自定义 Maven 插件。我将插件设置--enable-preview编译为编译器 arg,即

<plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-compiler-plugin</artifactId>
    <configuration>
        <compilerArgs>
            <compilerArg>--enable-preview</compilerArg>
        </compilerArgs>
    </configuration>
</plugin>
Run Code Online (Sandbox Code Playgroud)

当我想执行插件时,我在POM中添加这样的插件:

<plugin>
    <groupId>my.group</groupId>
    <artifactId>my-plugin</artifactId>
    <executions>
        <execution>
            <phase>generate-sources</phase>
            <goals>
                <goal>my-goal</goal>
            </goals>
        </execution>
    </executions>
</plugin>
Run Code Online (Sandbox Code Playgroud)

但这失败了:

Preview features are not enabled for MyPluginMojo. Try running with '--enable-preview'
Run Code Online (Sandbox Code Playgroud)

如何在插件执行中启用预览功能?

java maven-plugin maven

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

MongoDB反向正则表达式

我在MongoDB中有一个带有regex属性的文档

    {
        _id: ObjectId("516023189732da20ce000004"),
        regex: /^(my|your)\s+regex$/
    }
Run Code Online (Sandbox Code Playgroud)

我需要找回的是这样的文件db.col.find({regex: 'your regex'})db.col.find({regex: 'my regex'}).在MySQL中我会这样做:SELECT * FROM table WHERE 'my regex' REGEXP table.regex.我怎样才能在MongoDB中实现这一目标?

regex mongodb

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

jQuery的CORS身份验证

我已经阅读了很多有关CORS和身份验证的文档,而且我很确定可以正确执行操作。我正在尝试验证jQuery.ajax GET CORS请求,如下所示:

$.ajax('http://httpbin.org/basic-auth/foo/bar', {
    type: 'GET',
    username: 'foo',
    password: 'bar',
    xhrFields: {
        withCredentials: true
    }
}).then(function (data) {
    alert('success');
}, function (xhr) {
    alert('failure');
});
Run Code Online (Sandbox Code Playgroud)

但浏览器不断提示我输入凭据,而不发送所提供的凭据。在http://jsfiddle.net/BpYc3/上尝试此操作,其中http://httpbin.org应该发送正确的CORS标头。

javascript authentication ajax jquery cors

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

如何将Hibernate从MySQL迁移到SQL Server?

我需要将我的JPA/Hibernate(5.1)Java EE应用程序从MySQL迁移到SQL Server(2012).自从JPA提供抽象以来,我的谦虚思想就是简单明了.

我开始装上Wildfly 10的SQL服务器JDBC驱动程序4.2,从微软网站下载,并确定导致成功的连接测试新的数据源.

然后,我重新发布了我的应用程序让Hibernate重建数据库表,但我坚持这个:

13:27:29,268 WARN  [org.hibernate.engine.jdbc.spi.SqlExceptionHelper] (ServerService Thread Pool -- 61) SQL Error: 1038, SQLState: S0004
13:27:29,268 ERROR [org.hibernate.engine.jdbc.spi.SqlExceptionHelper] (ServerService Thread Pool -- 61) An object or column name is missing or empty. For SELECT INTO statements, verify each column has a name. For other statements, look for empty alias names. Aliases defined as "" or [] are not allowed. Change the alias to a valid name.
13:27:29,270 ERROR [org.jboss.msc.service.fail] (ServerService Thread Pool -- 61) MSC000001: Failed …
Run Code Online (Sandbox Code Playgroud)

java sql-server hibernate jpa wildfly

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

如何用Jackson反序列化Map &lt;?,?&gt;?

我正在尝试Map<?, ?>使用Jackson对象2.8 将带有任意对象的a序列化/反序列化为键。JSON对应项应为一对数组,即给定

public class Foo {
    public String foo;
    public Foo(String foo) {
        this.foo = foo;
    }
}

public class Bar {
    public String bar;
    public Bar(String bar) {
        this.bar = bar;
    }
}
Run Code Online (Sandbox Code Playgroud)

然后

Map<Foo, Bar> map;
map.put(new Foo("foo1"), new Bar("bar1"));
map.put(new Foo("foo2"), new Bar("bar2"));
Run Code Online (Sandbox Code Playgroud)

应该用这个JSON表示

[
    [ { "foo": "foo1" }, { "bar": "bar1" } ],
    [ { "foo": "foo2" }, { "bar": "bar2" } ]
]
Run Code Online (Sandbox Code Playgroud)

所以我做了序列化部分

public class MapToArraySerializer extends JsonSerializer<Map<?, ?>> { …
Run Code Online (Sandbox Code Playgroud)

java json jackson json-deserialization

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

访问 WebSocket @ServerEndpoint 中的 HttpServletRequest 属性

我需要访问HttpServletRequest属性以获取包含TLS 请求的证书数组的javax.servlet.request.X509CertificateX509Certificate

从 JAX-RSContainerRequestFilter我可以轻松地从ContainerRequestContext.getProperty(String property)方法中提取它,但是我找不到从 WebSocketSession或 中获取它的方法HandshakeRequest,从中我可以访问HttpSession实例但不能访问实例HttpServletRequest

注意:这不是Accessing HttpSession from HttpServletRequest in a Web Socket @ServerEndpoint因为我需要访问HttpServletRequest(或等效于提取 TLS 证书),而不是HttpSession.

由于 WebSocket 是 HTTP 的超集,我想它应该是可能的,希望 Java 团队已经想到了一种访问 servlet 属性的方法,但我真的找不到。任何人都知道这是否可能?

java servlets websocket java-websocket jakarta-ee

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