gpt4 book ai didi

java - RESTEasy 的 SpringContextLoaderListener 不扫描 @Path

转载 作者:行者123 更新时间:2023-11-30 08:23:21 24 4
gpt4 key购买 nike

我正在尝试实现 RESTEasy + Spring,但 @Autowire 不工作。我找到了一些引用,我需要使用 org.jboss.resteasy.plugins.spring.SpringContextLoaderListener 并禁用 resteasy 自动扫描。我试过了,但现在无法识别我的网络服务。我做错了什么?这是我的 web.xml

<?xml version="1.0" encoding="UTF-8" ?>

<web-app version="2.5" xmlns="http://java.sun.com/xml/ns/javaee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd">

<display-name>APF Web Service</display-name>

<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>
classpath:applicationContext.xml
</param-value>
</context-param>
<context-param>
<param-name>javax.faces.PROJECT_STAGE</param-name>
<param-value>Development</param-value>
</context-param>

<!-- REST configuration -->

<listener>
<listener-class>
org.jboss.resteasy.plugins.server.servlet.ResteasyBootstrap
</listener-class>
</listener>

<!-- RESTEasy <-> Spring connector (RESTEasy can access Spring beans) -->

<listener>
<listener-class>org.jboss.resteasy.plugins.spring.SpringContextLoaderListener</listener-class>
</listener>

<servlet>
<servlet-name>resteasy-servlet</servlet-name>
<servlet-class>
org.jboss.resteasy.plugins.server.servlet.HttpServletDispatcher
</servlet-class>
</servlet>

<servlet-mapping>
<servlet-name>resteasy-servlet</servlet-name>
<url-pattern>/json/*</url-pattern>
</servlet-mapping>

<context-param>
<param-name>resteasy.servlet.mapping.prefix</param-name>
<param-value>/json</param-value>
</context-param>

<!--<context-param>-->
<!--<param-name>resteasy.resources</param-name>-->
<!--<param-value>ApplicationSvc</param-value>-->
<!--</context-param>-->

<!-- End of REST configuration -->

</web-app>

这是我的网络服务

@Service
@Path("/json")
public class ApplicationSupportSvc {

@Autowired
private MobileSurveyApkRepo mobileSurveyApkRepo;

@GET
@Path("/latest")
@Produces(MediaType.APPLICATION_JSON)
@Transactional
public ApkResponse getLatestApk() {

return mobileSurveyApkRepo.getLatestApk();
}

}

这是我的 applicationContext.xml

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

<context:component-scan base-package="some.package" />
<context:annotation-config />
<aop:config proxy-target-class="true"></aop:config>

<bean id="dataSource" class="org.springframework.jndi.JndiObjectFactoryBean">
<property name="jndiName" value="jdbc/SomeConn" />
</bean>

<!-- Hibernate session factory -->

<bean id="sessionFactory"
class="org.springframework.orm.hibernate3.annotation.AnnotationSessionFactoryBean">

<property name="dataSource" ref="dataSource"/>

<property name="hibernateProperties">
<value>
<![CDATA[

hibernate.dialect=org.hibernate.dialect.SQLServerDialect
hibernate.default_schema=FIN
hibernate.hbm2ddl.auto=update
hibernate.hbm2ddl.keywords=auto-quote
hibernate.show_sql=true
javax.persistence.validation.mode=none

]]>
</value>
</property>

<property name="packagesToScan">
<list>
<value>some.package</value>
</list>
</property>

<property name="mappingLocations">
<list>
<value>classpath:jbpm.execution.hbm.xml</value>
<value>classpath:jbpm.history.hbm.xml</value>
<value>classpath:jbpm.task.hbm.xml</value>
<value>classpath:jbpm.repository.hbm.xml</value>
<value>classpath:jbpm.identity.hbm.xml</value>
</list>
</property>

</bean>

<bean id="transactionManager"
class="org.springframework.orm.hibernate3.HibernateTransactionManager">
<property name="sessionFactory" ref="sessionFactory" />
</bean>

<tx:annotation-driven transaction-manager="transactionManager" mode="aspectj" />

<!-- End of Hibernate session factory -->

<!-- jBPM4 Bean Definitions -->
<bean id="springHelper" class="org.jbpm.pvm.internal.processengine.SpringHelper">
<property name="jbpmCfg">
<value>jbpm.cfg.xml</value>
</property>
</bean>

<bean id="processEngine" factory-bean="springHelper"
factory-method="createProcessEngine" />

<bean id="repositoryService" factory-bean="processEngine"
factory-method="getRepositoryService" />

<bean id="executionService" factory-bean="processEngine"
factory-method="getExecutionService" />

<bean id="taskService" factory-bean="processEngine"
factory-method="getTaskService" />

<bean id="historyService" factory-bean="processEngine"
factory-method="getHistoryService" />

<bean id="managementService" factory-bean="processEngine"
factory-method="getManagementService" />

<!-- End of jBPM4 Bean Definitions -->

</beans>

我正在使用 RESTEasy 3.0.6 和 Spring 4.0.3,以及 JBOSS EAP 6.2

最佳答案

RESTEasy 和 Spring 4 存在错误:https://issues.jboss.org/browse/RESTEASY-1012

根据问题的描述创建您自己的 ContextLoaderListener 实现。

关于java - RESTEasy 的 SpringContextLoaderListener 不扫描 @Path,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23737848/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com