小编jos*_*737的帖子

没有名为X的EntityManager的持久性提供程序

我正在使用JPA开发JavaSE应用程序.不幸的是,我null打电话后: Persistence.createEntityManagerFactory(PERSISTENCE_UNIT_NAME);

您将在下面找到:

  • 我的代码片段,调用EntityManagerFactory并意外返回null
  • 我的persistence.xml档案
  • 我的项目结构

我的代码片段:

public class Main {
    private static final String PERSISTENCE_UNIT_NAME = "MeineJpaPU";
    private static EntityManagerFactory factory;

    public static void main(String[] args) {
        // I get null on this line!!!
       factory = Persistence.createEntityManagerFactory(PERSISTENCE_UNIT_NAME);

       EntityManager em = factory.createEntityManager();
       // do stuff with entity manager
       ...
    }
}
Run Code Online (Sandbox Code Playgroud)

我的persistence.xml:

<?xml version="1.0" encoding="UTF-8"?>
<persistence version="1.0"
    xmlns="http://java.sun.com/xml/ns/persistence"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://java.sun.com/xml/ns/persistence
                        http://java.sun.com/xml/ns/persistence/persistence_1_0.xsd">
  <persistence-unit name="MeineJpaPU" transaction-type="RESOURCE_LOCAL">
    <provider>org.apache.openjpa.persistence.PersistenceProviderImpl</provider>
    <class>path.to.package.server.Todo</class>
      <exclude-unlisted-classes>false</exclude-unlisted-classes>
     <properties>       
            <property name="javax.persistence.jdbc.driver" value="org.postgresql.Driver"/>       
            <property name="javax.persistence.jdbc.url" …
Run Code Online (Sandbox Code Playgroud)

java jpa entitymanager persistence.xml java-ee

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

如何为HTTP GET的多个Key-Value参数设计REST URI

我正在设计一个RESTful API.

一项服务应为多个键值对提供查询功能.例如,客户端可以使用一个HTTP GET请求查询不同的产品和相关数量.

客户想要使用金额44和产品2查询产品1,金额为55.我实际上不希望我的URI看起来像这样:

/produkt?productId1=1&productquantity1=44&productId2=2&productquantity2=55
Run Code Online (Sandbox Code Playgroud)

因为我不知道有多少产品被查询.

或者像这样:

/produkt?product=1,44&product=2,55
Run Code Online (Sandbox Code Playgroud)

因为客户怎么能知道在逗号之前有productId和逗号之后的数量.

有没有人有其他解决方案?或者,提供使用一个请求查询多个产品的可能性是不是RESTful?是否更好地提供仅查询一个具有相关数量的产品的可能性,如果客户想要查询更多产品,他们应该发送更多请求?

java rest soa web-services http

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

版本化REST API和供应商特定的内容类型

我在这个主题中阅读了很多关于REST API版本的内容:API版本化的最佳实践?

因此,我想使用HTTP-Accept-Header来指示客户端要求的版本.但是如何在我的应用程序中应用它?因此,有哪些变化?编组员如何知道应该使用哪个版本?我必须注册我的类型吗?

我所知道的是我必须更改@Produces-Annotation 的内容

@GET
@Path("/locations")
@Produces("application/vnd.mycompany-v1+xml")
Location[] getLocations();
Run Code Online (Sandbox Code Playgroud)

但还有什么必须改变?

java versioning rest jax-rs http-headers

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

如何测试 SOAP 服务?

你们如何测试您的 SOAP 服务?你使用类似的工具soapUI还是你写的Unit Tests?只是想听听一些意见,你更喜欢什么,两种方法的优点或缺点是什么?如果有人写Unit Tests,你能举个例子如何写吗???

编辑:我开发了很多 REST 服务,我通常使用 JUnit 和 REST 客户端框架进行测试。因此,当部署 REST 服务时,我能够使用 http 连接将这些服务作为 JUnit 测试来调用。SOAP 中也有类似的东西吗?有人有 SOAP 客户端的示例代码吗?

java soa junit soap web-services

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

Resteasy,使用RestEasy的服务器端模拟框架制作Http-Put或Http-Post

我写了一个Rest-Service,我想测试一下.我想在没有运行服务器的情况下运行JUnit测试.为此,我使用RestEasy的服务器端模拟框架.

我的问题是,如何使用这个框架在Http-Body中使用编组的Java对象来发出Http-Put或Http-Post请求?

下面的代码适用于Http-Get,但如何制作Put或Post,也许有人为此获得了一些示例代码?

@Test
public void testClient() throws Exception {

    Dispatcher dispatcher = MockDispatcherFactory.createDispatcher();

    POJOResourceFactory noDefaults = new POJOResourceFactory(
            MyClass.class);
    dispatcher.getRegistry().addResourceFactory(noDefaults);

    {
        MockHttpRequest request = MockHttpRequest.get("/message/test/"
                + requestParam);
        MockHttpResponse response = new MockHttpResponse();

        dispatcher.invoke(request, response);
        assertEquals(HttpServletResponse.SC_OK, response.getStatus());

    }
}
Run Code Online (Sandbox Code Playgroud)

rest unit-testing http jax-rs resteasy

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