我有一个带有Spring Core 4框架的gwt应用程序。在服务器部分,我添加了RestController来为其他应用程序生成Web服务。我为此使用Java配置,但是现在当我在嵌入式服务器Jetty中运行该应用程序时,gwt应用程序可以完美运行,但不能运行Web Service(错误404),而当我在jboss 7.1.1中运行war时,其余WebService可以完美运行,但不能正常运行gwt应用程序(错误404)。
这是我的新配置:
@RestController
@RequestMapping(value = "/historiquedlo", produces = "application/hal+json", consumes = { "text/plain","text/html","application/*" })
@Transactional
public class WsHistoriqueDlo {
/**
* En dur dans PCD
*/
private static final String DEFAULT_CODE_PRODUIT_DL = "L20";
@Autowired
private EntityManager entityManager;
/**
* Méthode avec 4 paramètres : Code produit par défaut L20
*
* @param siren
* @param debut
* : ISO Date Format yyyy-MM-dd, e.g. "2000-10-31".
* @param sirenGroupe
* @param sirenTeteGroupe
* @return ResponseEntity<Resources<HistoriqueDlo>>
*/
@RequestMapping(value = "/{siren}/{debut}", method = RequestMethod.GET)
public ResponseEntity<Resource<InfoHistoriqueDlo>> findHistoriqueDlo(@PathVariable("siren") final String siren,
@PathVariable("debut") @DateTimeFormat(iso = DateTimeFormat.ISO.DATE) final String debut,
@RequestParam(name="sirenGroupe", required=false) final String sirenGroupe,
@RequestParam(name="sirenTeteGroupe", required=false) final String sirenTeteGroupe) {
.
.
.}
public class SoftWebInitializer extends AbstractAnnotationConfigDispatcherServletInitializer {
@Override
protected Class<?>[] getRootConfigClasses() {
return new Class[] { SoftWebConfig.class };
}
@Override
protected Class<?>[] getServletConfigClasses() {
return null;
}
@Override
protected String[] getServletMappings() {
return new String[]{"/*","/ws/*"}; }
}
对于SoftWebConfig,我使用了以下配置:
@Configuration
@Import(SoftDBConfig.class)
@EnableScheduling
@EnableWebMvc
@EnableHypermediaSupport(type = { HypermediaType.HAL })
@ComponentScan(basePackages = { "com.rcibanque.socle.server.*", "com.rcibanque.sof.server.*",
"com.rcibanque.socle.server.ws.*" })
public class SoftWebConfig implements SchedulingConfigurer {
@Override
public void configureTasks(ScheduledTaskRegistrar taskRegistrar) {
taskRegistrar.setScheduler(taskExecutor());
}
@Bean(name = "TOPCAR-EXECUTOR", destroyMethod = "shutdown")
public Executor taskExecutor() {
return Executors.newScheduledThreadPool(1);
}
}
我的web.xml是这样的:
> <?xml version="1.0" encoding="UTF-8"?> <web-app
> 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" version="2.5" xmlns="http://java.sun.com/xml/ns/javaee">
>
> <display-name>rci_sof</display-name>
>
>
> <!-- Servlet de démarrage de l'application --> <servlet>
> <servlet-name>AppContextInitializerServlet</servlet-name>
> <servlet-class>com.rcibanque.sof.server.servlet.SofContextInitializerServlet</servlet-class>
> <load-on-startup>1</load-on-startup> </servlet>
>
> <!-- Services RPC --> <servlet>
> <servlet-name>dataServiceRPC</servlet-name>
> <servlet-class>com.rcibanque.sof.server.service.data.SofDataServiceImpl</servlet-class>
> </servlet> <servlet-mapping>
> <servlet-name>dataServiceRPC</servlet-name>
> <url-pattern>/rci_sof/dataService.rpc</url-pattern>
> </servlet-mapping> <servlet-mapping>
> <servlet-name>dataServiceRPC</servlet-name>
> <url-pattern>/rci_admin/dataService.rpc</url-pattern>
> </servlet-mapping>
>
> <servlet> <servlet-name>dataModuleServiceRPC</servlet-name>
> <servlet-class>com.rcibanque.sof.server.service.data.SofDataModuleServiceImpl</servlet-class>
> </servlet> <servlet-mapping>
> <servlet-name>dataModuleServiceRPC</servlet-name>
> <url-pattern>/rci_sof/dataModuleService.rpc</url-pattern>
> </servlet-mapping> <servlet-mapping>
> <servlet-name>dataModuleServiceRPC</servlet-name>
> <url-pattern>/rci_admin/dataModuleService.rpc</url-pattern>
> </servlet-mapping>
>
> <servlet> <servlet-name>tariffingServiceRPC</servlet-name>
> <servlet-class>com.rcibanque.sof.server.service.tariffing.TariffingServiceImpl</servlet-class>
> </servlet> <servlet-mapping>
> <servlet-name>tariffingServiceRPC</servlet-name>
> <url-pattern>/rci_sof/tariffingService.rpc</url-pattern>
> </servlet-mapping> <servlet-mapping>
> <servlet-name>tariffingServiceRPC</servlet-name>
> <url-pattern>/rci_admin/tariffingService.rpc</url-pattern>
> </servlet-mapping>
>
> <!-- RPC Chart --> <servlet> <servlet-name>chartRPC</servlet-name>
> <servlet-class>com.rcibanque.sof.server.chart.ChartGeneratorImpl</servlet-class>
> </servlet> <servlet-mapping> <servlet-name>chartRPC</servlet-name>
> <url-pattern>/rci_sof/chart.rpc</url-pattern> </servlet-mapping>
>
> <!-- RPC Print Report --> <servlet>
> <servlet-name>printReportRPC</servlet-name>
> <servlet-class>com.rcibanque.sof.server.print.report.SofPrintReportImpl</servlet-class>
> </servlet> <servlet-mapping>
> <servlet-name>printReportRPC</servlet-name>
> <url-pattern>/rci_sof/printReport.rpc</url-pattern>
> </servlet-mapping>
>
> <!-- RPC Mail --> <servlet>
> <servlet-name>messagingServiceRPC</servlet-name>
> <servlet-class>com.rcibanque.sof.server.print.messaging.SofMessagingServiceImpl</servlet-class>
> </servlet> <servlet-mapping>
> <servlet-name>messagingServiceRPC</servlet-name>
> <url-pattern>/rci_sof/messagingService.rpc</url-pattern>
> </servlet-mapping>
>
> <!-- RPC TOPCAR --> <servlet>
> <servlet-name>topCarServiceRPC</servlet-name>
> <servlet-class>com.rcibanque.sof.server.service.topcar.TopCarService</servlet-class> </servlet> <servlet-mapping>
> <servlet-name>topCarServiceRPC</servlet-name>
> <url-pattern>/rci_sof/topCarService.rpc</url-pattern>
> </servlet-mapping> <servlet-mapping>
> <servlet-name>topCarServiceRPC</servlet-name>
> <url-pattern>/rci_admin/topCarService.rpc</url-pattern>
> </servlet-mapping>
>
> <!-- RPC Fiscalité CO2 --> <servlet>
> <servlet-name>fiscaliteCO2</servlet-name>
> <servlet-class>com.rcibanque.socle.server.service.data.FiscaliteCO2Service</servlet-class>
> </servlet> <servlet-mapping>
> <servlet-name>fiscaliteCO2</servlet-name>
> <url-pattern>/rci_sof/fiscaliteCO2Service.rpc</url-pattern>
> </servlet-mapping> <servlet-mapping>
> <servlet-name>fiscaliteCO2</servlet-name>
> <url-pattern>/rci_admin/fiscaliteCO2Service.rpc</url-pattern>
> </servlet-mapping>
>
> <!-- RPC Offre --> <servlet>
> <servlet-name>offreServiceRPC</servlet-name>
> <servlet-class>com.rcibanque.sof.server.service.offre.OffreServiceRPCImpl</servlet-class>
> </servlet> <servlet-mapping>
> <servlet-name>offreServiceRPC</servlet-name>
> <url-pattern>/rci_sof/offreService.rpc</url-pattern>
> </servlet-mapping>
>
> <!-- Servlets --> <servlet>
> <servlet-name>displayChartServlet</servlet-name>
> <servlet-class>org.jfree.chart.servlet.DisplayChart</servlet-class>
> </servlet> <servlet-mapping>
> <servlet-name>displayChartServlet</servlet-name>
> <url-pattern>/rci_sof/displayChart</url-pattern> </servlet-mapping>
>
> <servlet> <servlet-name>downloadServlet</servlet-name>
> <servlet-class>com.rcibanque.socle.server.servlet.DownloadServlet</servlet-class>
> </servlet> <servlet-mapping>
> <servlet-name>downloadServlet</servlet-name>
> <url-pattern>*.pdf</url-pattern> </servlet-mapping>
> <servlet-mapping> <servlet-name>downloadServlet</servlet-name>
> <url-pattern>*.xls</url-pattern> </servlet-mapping>
> <servlet-mapping> <servlet-name>downloadServlet</servlet-name>
> <url-pattern>*.txt</url-pattern> </servlet-mapping>
> <servlet-mapping> <servlet-name>downloadServlet</servlet-name>
> <url-pattern>*.csv</url-pattern> </servlet-mapping>
>
> <servlet> <servlet-name>topcarDownloadServlet</servlet-name>
> <servlet-class>com.rcibanque.socle.server.servlet.TopcarDownloadServlet</servlet-class>
> </servlet> <servlet-mapping>
> <servlet-name>topcarDownloadServlet</servlet-name>
> <url-pattern>/rci_sof/download</url-pattern> </servlet-mapping>
> <servlet> <servlet-name>uploadServlet</servlet-name>
> <servlet-class>com.rcibanque.socle.server.servlet.UploadServlet</servlet-class>
> </servlet> <servlet-mapping>
> <servlet-name>uploadServlet</servlet-name>
> <url-pattern>/rci_sof/upload</url-pattern> </servlet-mapping>
> <servlet-mapping> <servlet-name>uploadServlet</servlet-name>
> <url-pattern>/rci_admin/upload</url-pattern> </servlet-mapping>
> <servlet> <servlet-name>uploadTopcarServlet</servlet-name>
> <servlet-class>com.rcibanque.socle.server.servlet.UploadTopcarServlet</servlet-class>
> </servlet> <servlet-mapping>
> <servlet-name>uploadTopcarServlet</servlet-name>
> <url-pattern>/rci_sof/uploadTopcar</url-pattern> </servlet-mapping>
>
>
> <!-- Filtre de gestion des caches --> <filter>
> <filter-name>gwtCacheControlFilter</filter-name>
> <filter-class>com.rcibanque.socle.server.filter.GWTCacheControlFilter</filter-class>
> </filter> <filter-mapping>
> <filter-name>gwtCacheControlFilter</filter-name>
> <url-pattern>/*</url-pattern> </filter-mapping>
>
> <!-- Default page to serve --> <welcome-file-list>
> <welcome-file>Index.html</welcome-file> </welcome-file-list>
>
> <!-- Timeout QC32499 session connexion timeout <session-config>
> <session-timeout>300</session-timeout> </session-config> -->
>
> </web-app>
我在gwt应用程序中使用了http://localhost:8080/rci_sof/Index.html 对于网络服务,我使用以下网址:http://localhost:8080/rci_sof/ws/historiquedlo/30365637500209/L20/2018-06-20?sirenGroupe=950425694&sirenTeteGroupe=447938036。
谢谢。
答案 0 :(得分:0)
您可以使用web.xml
文件初始化应用程序
或
使用AbstractAnnotationConfigDispatcherServletInitializer.class
(从Servlet 3.0+开始)。
目前,您同时提供这两种服务,只有一种可以使用。
最简单的方法可能是在web.xml
中初始化调度程序servlet并删除SoftWebInitializer.class
。
将此添加到您的web.xml(使用适用于您的SoftWebConfig的正确路径):
现在,所有spring控制器都将具有基本URL localhost:8080/ws
<servlet>
<servlet-name>dispatcherServlet</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
<load-on-startup>1</load-on-startup>
<init-param>
<param-name>contextClass</param-name>
<param-value>org.springframework.web.context.support.AnnotationConfigWebApplicationContext</param-value>
</init-param>
<init-param>
<param-name>contextConfigLocation</param-name>
<param-value>XXXXX.XXXXX.SoftWebConfig</param-value>
</init-param>
</servlet>
<servlet-mapping>
<servlet-name>dispatcherServlet</servlet-name>
<url-pattern>/ws/*</url-pattern>
</servlet-mapping>
使用弹簧WebApplicationInitializer而不是web.xml
文件仅在Servlet 3.0+版本中有效,但是您的web.xml当前指定的版本是2.5。
因此,要实际使用AbstractAnnotationConfigDispatcherServletInitializer
,您将必须删除web.xml
文件并将所有内容迁移到新的Initializer文件。
还需要支持Servlet 3.0及更高版本的Web服务器。 Jetty would require at least version 8。