小编zer*_*021的帖子

Guice:Binder#bindConstant()和Binder#bind()... toInstance之间的区别

我想问一下有什么区别

bindConstant().annotatedWith(Names.named("keepAliveInterval")).to(60);
Run Code Online (Sandbox Code Playgroud)

bind(Integer.TYPE).annotatedWith(Names.named("keepAliveInterval")).toInstance(60);
Run Code Online (Sandbox Code Playgroud)

我想用Names.bindProperties(binder(),prop)加载我的所有配置属性; 在我的模块中,我发现它使用后者来绑定属性.

感谢和问候

马雷克

java config constants guice

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

是否可以使用可变数量的URI参数配置JAX-RS方法?

是否可以配置GET方法来读取可变数量的URI参数并将它们解释为变量参数(数组)或集合?我知道查询参数可以作为列表/集读取,但在我的情况下我不能用它们.

例如:

@GET
@Produces("text/xml")
@Path("list/{taskId}")
public String getTaskCheckLists(@PathParam("taskId") int... taskId) {
    return Arrays.toString(taskId);
}
Run Code Online (Sandbox Code Playgroud)

提前致谢

java rest web-services jax-rs jersey

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

如何防止"本地事务已经有1个非XA资源"异常?

我在无状态EJB中使用2 PU,并且在一个方法上调用它们:

@PersistenceContext(unitName="PU")
private EntityManager em;
@PersistenceContext(unitName="PU2")
private EntityManager em2;

@TransactionAttribute(TransactionAttributeType.REQUIRES_NEW )
public void getCandidates(final Integer eventId) throws ControllerException {
    ElectionEvent electionEvent = em.find(ElectionEvent.class, eventId);
    ...
    Person person = getPerson(candidate.getLogin());
    ...
}

@TransactionAttribute(TransactionAttributeType.REQUIRES_NEW )
private Person getPerson(String login) throws ControllerException {
    Person person = em2.find(Person.class, login);
    return person;
}
Run Code Online (Sandbox Code Playgroud)

这些方法使用REQUIRES_NEW transcaction注释以避免此异常.当我从javaFX applet调用这些方法时,所有方法都按预期工作.现在我试图从JAX-RS webservice调用它们(我没有看到任何逻辑上的区别,因为在初始上下文中查找了ejb两种情况)并且我一直得到这个异常.当我在glassfish 2.1连接池中设置XADatasource时,我在em2上得到了nullpointer异常.

任何想法接下来要尝试什么?

问候

java persistence ejb transactions jax-rs

8
推荐指数
2
解决办法
7602
查看次数

如何覆盖默认的maven-install-plugin行为?

我需要自定义工件安装,无法计算如何覆盖默认工件(从默认的maven生命周期).所以我的问题是:

如何在我的pom.xml中配置maven安装插件,这样它就不会执行默认安装并只执行我的自定义安装文件目标?

我尝试没有id和默认安装 ID,但它没有帮助.

更新: 从提供的答案 - 这对我不起作用(我在日志中看到两次安装尝试).

<pluginManagement>
  <plugins>
    <plugin>
      <groupId>org.apache.maven.plugins</groupId>
      <artifactId>maven-install-plugin</artifactId>
      <executions>
        <execution>
          <id>default-install</id>
          <phase>none</phase>
        </execution>
      </executions>
    </plugin>
  </plugins>
</pluginManagement>
<plugins>
  <plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-install-plugin</artifactId>
    <version>2.3.1</version>
    <executions>
      <execution>
        <id>install-jar-lib</id>
        <goals>
          <goal>install-file</goal>
        </goals>
        <phase>install</phase>
        <configuration>
          <file>${project.build.directory}/${project.build.finalName}.jar</file>
          <generatePom>false</generatePom>
          <pomFile>pom.xml</pomFile>
          <packaging>jar</packaging>
          <version>${unicorn.version}</version>
        </configuration>
      </execution>
    </executions>
  </plugin>
Run Code Online (Sandbox Code Playgroud)

overriding default maven

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