小编Mic*_*ech的帖子

我是否需要persistence.xml中的<class>元素?

我有非常简单的persistance.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="eventractor" transaction-type="RESOURCE_LOCAL">
        <class>pl.michalmech.eventractor.domain.User</class>
        <class>pl.michalmech.eventractor.domain.Address</class>
        <class>pl.michalmech.eventractor.domain.City</class>
        <class>pl.michalmech.eventractor.domain.Country</class>

        <properties>
            <property name="hibernate.hbm2ddl.auto" value="validate" />
            <property name="hibernate.show_sql" value="true" />
        </properties>
    </persistence-unit>

</persistence>
Run Code Online (Sandbox Code Playgroud)

它的工作原理.

但是当我删除<class>元素时,应用程序看不到实体(所有类都带有注释@Entity).

是否有任何自动机制来扫描@Entity类?

java orm annotations hibernate jpa

106
推荐指数
7
解决办法
15万
查看次数

TestNG是否有像SpringJUnit4ClassRunner这样的跑步者

当我在JUnit中编写测试时(在Spring上下文中)我通常这样做:

@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration("classpath:testContext.xml")
public class SimpleTest {

    @Test
    public void testMethod() {
        // execute test logic...
    }
}
Run Code Online (Sandbox Code Playgroud)

我怎么能用TestNG做同样的事情?


我会添加更多细节.使用AbstractTestNGSpringContextTests它可以工作,但不是我想要的方式.我有一些测试......

@ContextConfiguration(locations = { "classpath:applicationContextForTests.xml" })
public class ExampleTest extends AbstractTestNGSpringContextTests {

    private Boolean someField;

    @Autowired
    private Boolean someBoolean;

    @Test
    public void testMethod() {
        System.out.println(someField);
        Assert.assertTrue(someField);
    }

    @Test
    public void testMethodWithInjected() {
        System.out.println(someBoolean);
        Assert.assertTrue(someBoolean);
    }

    // setters&getters
}
Run Code Online (Sandbox Code Playgroud)

和描述符......

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd">

    <bean id="exampleTest" class="pl.michalmech.ExampleTest">
        <property name="someField">
            <ref bean="someBoolean"/>
        </property>
    </bean>

    <bean id="someBoolean" class="java.lang.Boolean">
        <constructor-arg type="java.lang.String" …
Run Code Online (Sandbox Code Playgroud)

java junit testng spring

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

如何通过CXF中的Interceptor将SoapFault转换为SoapMessage?

我通过Spring和创建并配置了Web服务CXF.见下面的豆子:

<?xml version="1.0" encoding="UTF-8"?>
<beans <!-- ommited -->>
    <import resource="classpath:META-INF/cxf/cxf.xml" />
    <import resource="classpath:META-INF/cxf/cxf-extension-soap.xml" />
    <import resource="classpath:META-INF/cxf/cxf-servlet.xml" />

    <bean id="internalActService" class="package.InternalActServiceImpl" />

    <jaxws:endpoint implementor="#internalActService" address="/InternalActService">
        <jaxws:properties>
            <entry key="schema-validation-enabled" value="true" />
        </jaxws:properties>

        <jaxws:outFaultInterceptors>
            <bean class="package.InternalActServiceFaultOutInterceptor" />
        </jaxws:outFaultInterceptors>
    </jaxws:endpoint>
</beans>
Run Code Online (Sandbox Code Playgroud)

您可以看到我在我的Web服务中添加了模式验证.但是当请求与模式不对应时CXF抛出SoapFault.我想发送给客户SoapMessage而不是SoapFault,这就是我添加的原因outFaultInterceptors.

我的问题是如何将SoapFault 转换为SoapMessage?我做了几次尝试,但我不知道如何实施outFaultInterceptor.

java web-services cxf jax-ws

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

标签 统计

java ×3

annotations ×1

cxf ×1

hibernate ×1

jax-ws ×1

jpa ×1

junit ×1

orm ×1

spring ×1

testng ×1

web-services ×1