首页 文章

如何在arquillian嵌入式容器中为wildfly 8.2注入SessionContext

提问于
浏览
0

添加该行后,我的wildfly服务器没有运行

@Resource private SessionContext sessionContext;

如何使用wildfly 8.2版本在嵌入式arquillian中注入会话上下文???我甚至试图添加这条线

.addAsWebInfResource(新文件(“D:\ wildfly-.2.0.Final \ domain \ configuration \ domain.xml”))提到我的野生苍蝇服务器的domain.xml,其中我创建了用户 . 但又无法启动服务器 . 此外,当我删除注入SessionContext的行时,我的服务器正常启动 .

@RunWith(Arquillian.class)

public class CRLManagerTest {

private static final Logger LOGGER = LoggerFactory.getLogger(CRLManagerTest.class);

@Deployment
public static WebArchive createDeployment() {

    WebArchive  webArchive = ShrinkWrap.create(WebArchive.class, "test.war")
            .addClass(CrManagerFacade1.class)
            .addClass(SessionContext.class)
            .addClass(CrManagerFacade.class)
            .addClass(CrManager.class)

            .addAsResource("META-INF/persistence.xml", "META-INF/persistence.xml")
            .addAsWebInfResource(new File("D:\\wildfly-.2.0.Final\\domain\\configuration\\domain.xml"))
            .addAsWebInfResource(EmptyAsset.INSTANCE, "beans.xml") .addAsManifestResource("META-INF/persistence.xml", "persistence.xml") .addAsManifestResource(EmptyAsset.INSTANCE, "beans.xml")
            ;
    return webArchive;
}
@Resource
private SessionContext sessionContext;

@Test
public void testUpdateReceipt1() throws Exception {
    LOGGER.info(">>>>>>>>>>>>> This is a test");
    Assert.assertEquals("hello","hello");
}

这是我的arquillian.xml

<container qualifier="jboss-managed" default="true">
    <configuration>
        <property name="jbossHome">${jbossHome}</property>          
    </configuration>
</container>

2 回答

  • 0

    看起来你没有使用Servlet协议,所以Arquillian没有做一个http请求,这意味着什么都不依赖于servlet或Request / Session中的任何东西都可用 . Wildfly默认不使用servlet协议,因此您需要启用它 .

    将其添加到arquillian.xml:

    <!-- Sets the protocol which is how Arquillian talks and executes the tests inside the container -->
    <defaultProtocol type="Servlet 3.0" />
    

    这到你的pom.xml:

    <dependency>
        <groupId>org.jboss.arquillian.protocol</groupId>
        <artifactId>arquillian-protocol-servlet</artifactId>
        <scope>test</scope>
    </dependency>
    
  • 0

    正确的答案是在ShrinkWrat.create方法中添加classess .

    .addClasses(CRLManagerTest.class,CrManagerFacade.class,CrManager.class)

相关问题