简体   繁体   English

在JBoss Wildfly服务器上运行Spring应用程序

[英]Run a Spring Application on a JBoss Wildfly Server

I have an Java project (of RESTful Services) I developed on a Windows machine in Eclipse and runs on a Wildfly 10 Server. 我有一个Java项目(基于RESTful Services),是在Eclipse的Windows计算机上开发的,并在Wildfly 10服务器上运行。 Everything works perfectly. 一切正常。 Now I am trying to deploy the same project on Eclipse on a OSX machine. 现在,我试图在OSX机器上的Eclipse上部署相同的项目。

I have installed Eclipse Neon 2 and imported the Java project. 我已经安装了Eclipse Neon 2并导入了Java项目。 I have also installed a Wildfly 10 Server. 我还安装了Wildfly 10服务器。 The Java project has been published to the server. Java项目已发布到服务器。 I can start the server, and access the Welcome to WildFly page on: 我可以启动服务器,并在以下位置访问“ Welcome to WildFly页面:

localhost:8080/

Also in the console, you can see that the Spring RESTful services all load: 同样在控制台中,您可以看到Spring RESTful服务全部加载:

eg 例如

Mapped "{[/category/list],methods=[GET],produces=[application/json]}" onto public org.springframework.http.ResponseEntity<java.util.List<com.jobs.spring.domain.Category>> com.jobs.spring.controller.CategoryRESTService.findAllCategorys()

在此处输入图片说明

The server logs are identical to the Windows environment. 服务器日志与Windows环境相同。

20:39:10,051 INFO  [org.jboss.modules] (main) JBoss Modules version 1.5.2.Final
20:39:20,242 INFO  [org.jboss.msc] (main) JBoss MSC version 1.2.6.Final
20:39:20,309 INFO  [org.jboss.as] (MSC service thread 1-6) WFLYSRV0049: WildFly Full 10.1.0.Final (WildFly Core 2.2.0.Final) starting
20:39:21,277 INFO  [org.jboss.as.server.deployment.scanner] (DeploymentScanner-threads - 1) WFLYDS0004: Found jbosswildfly-1.0.war in deployment directory. To trigger deployment create a file called jbosswildfly-1.0.war.dodeploy
20:39:21,316 INFO  [org.jboss.as.server] (Controller Boot Thread) WFLYSRV0039: Creating http management service using socket-binding (management-http)
20:39:21,332 INFO  [org.xnio] (MSC service thread 1-1) XNIO version 3.4.0.Final
20:39:21,339 INFO  [org.xnio.nio] (MSC service thread 1-1) XNIO NIO Implementation Version 3.4.0.Final
20:39:21,370 INFO  [org.jboss.as.clustering.infinispan] (ServerService Thread Pool -- 38) WFLYCLINF0001: Activating Infinispan subsystem.
20:39:21,374 INFO  [org.jboss.as.naming] (ServerService Thread Pool -- 46) WFLYNAM0001: Activating Naming Subsystem
20:39:21,384 INFO  [org.jboss.as.security] (ServerService Thread Pool -- 53) WFLYSEC0002: Activating Security Subsystem
20:39:21,388 INFO  [org.wildfly.extension.io] (ServerService Thread Pool -- 37) WFLYIO001: Worker 'default' has auto-configured to 16 core threads with 128 task threads based on your 8 available processors
20:39:21,384 WARN  [org.jboss.as.txn] (ServerService Thread Pool -- 54) WFLYTX0013: Node identifier property is set to the default value. Please make sure it is unique.
20:39:21,390 INFO  [org.jboss.as.security] (MSC service thread 1-5) WFLYSEC0001: Current PicketBox version=4.9.6.Final
20:39:21,406 INFO  [org.jboss.as.jsf] (ServerService Thread Pool -- 44) WFLYJSF0007: Activated the following JSF Implementations: [main]
20:39:21,419 INFO  [org.jboss.as.webservices] (ServerService Thread Pool -- 56) WFLYWS0002: Activating WebServices Extension
20:39:21,533 INFO  [org.jboss.as.naming] (MSC service thread 1-5) WFLYNAM0003: Starting Naming Service
20:39:21,543 INFO  [org.jboss.as.connector] (MSC service thread 1-5) WFLYJCA0009: Starting JCA Subsystem (WildFly/IronJacamar 1.3.4.Final)
20:39:21,549 INFO  [org.wildfly.extension.undertow] (MSC service thread 1-4) WFLYUT0003: Undertow 1.4.0.Final starting
20:39:21,545 INFO  [org.jboss.as.mail.extension] (MSC service thread 1-1) WFLYMAIL0001: Bound mail session [java:jboss/mail/Default]
20:39:21,554 INFO  [org.jboss.remoting] (MSC service thread 1-8) JBoss Remoting version 4.0.21.Final
20:39:21,552 INFO  [org.jboss.as.connector.subsystems.datasources] (ServerService Thread Pool -- 33) WFLYJCA0004: Deploying JDBC-compliant driver class org.h2.Driver (version 1.3)
20:39:21,568 INFO  [org.jboss.as.connector.deployers.jdbc] (MSC service thread 1-2) WFLYJCA0018: Started Driver service with driver-name = h2
20:39:21,695 INFO  [org.wildfly.extension.undertow] (ServerService Thread Pool -- 55) WFLYUT0014: Creating file handler for path '/Users/richardmarais/Development/servers/wildfly-10.1.0.Final/welcome-content' with options [directory-listing: 'false', follow-symlink: 'false', case-sensitive: 'true', safe-symlink-paths: '[]']
20:39:21,704 INFO  [org.wildfly.extension.undertow] (MSC service thread 1-6) WFLYUT0012: Started server default-server.
20:39:21,708 INFO  [org.wildfly.extension.undertow] (MSC service thread 1-6) WFLYUT0018: Host default-host starting
20:39:21,843 INFO  [org.jboss.as.ejb3] (MSC service thread 1-5) WFLYEJB0482: Strict pool mdb-strict-max-pool is using a max instance size of 32 (per class), which is derived from the number of CPUs on this host.
20:39:21,844 INFO  [org.jboss.as.ejb3] (MSC service thread 1-7) WFLYEJB0481: Strict pool slsb-strict-max-pool is using a max instance size of 128 (per class), which is derived from thread worker pool sizing.
20:39:21,846 INFO  [org.wildfly.extension.undertow] (MSC service thread 1-8) WFLYUT0006: Undertow HTTP listener default listening on 127.0.0.1:8080
20:39:22,063 WARN  [org.jboss.as.domain.management.security] (MSC service thread 1-7) WFLYDM0111: Keystore /Users/richardmarais/Development/servers/wildfly-10.1.0.Final/standalone/configuration/application.keystore not found, it will be auto generated on first use with a self signed certificate for host localhost
20:39:22,083 INFO  [org.jboss.as.server.deployment.scanner] (MSC service thread 1-5) WFLYDS0013: Started FileSystemDeploymentService for directory /Users/richardmarais/Development/servers/wildfly-10.1.0.Final/standalone/deployments
20:39:22,096 INFO  [org.jboss.as.server.deployment] (MSC service thread 1-6) WFLYSRV0027: Starting deployment of "jbosswildfly-1.0.war" (runtime-name: "jbosswildfly-1.0.war")
20:39:22,315 INFO  [org.infinispan.factories.GlobalComponentRegistry] (MSC service thread 1-2) ISPN000128: Infinispan version: Infinispan 'Chakra' 8.2.4.Final
20:39:22,351 INFO  [org.infinispan.configuration.cache.EvictionConfigurationBuilder] (ServerService Thread Pool -- 65) ISPN000152: Passivation configured without an eviction policy being selected. Only manually evicted entities will be passivated.
20:39:22,351 INFO  [org.infinispan.configuration.cache.EvictionConfigurationBuilder] (ServerService Thread Pool -- 63) ISPN000152: Passivation configured without an eviction policy being selected. Only manually evicted entities will be passivated.
20:39:22,351 INFO  [org.infinispan.configuration.cache.EvictionConfigurationBuilder] (ServerService Thread Pool -- 59) ISPN000152: Passivation configured without an eviction policy being selected. Only manually evicted entities will be passivated.
20:39:22,352 INFO  [org.infinispan.configuration.cache.EvictionConfigurationBuilder] (ServerService Thread Pool -- 65) ISPN000152: Passivation configured without an eviction policy being selected. Only manually evicted entities will be passivated.
20:39:22,353 INFO  [org.infinispan.configuration.cache.EvictionConfigurationBuilder] (ServerService Thread Pool -- 63) ISPN000152: Passivation configured without an eviction policy being selected. Only manually evicted entities will be passivated.
20:39:22,353 INFO  [org.infinispan.configuration.cache.EvictionConfigurationBuilder] (ServerService Thread Pool -- 59) ISPN000152: Passivation configured without an eviction policy being selected. Only manually evicted entities will be passivated.
20:39:22,359 INFO  [org.wildfly.extension.undertow] (MSC service thread 1-4) WFLYUT0006: Undertow HTTPS listener https listening on 127.0.0.1:8443
20:39:22,705 INFO  [org.jboss.ws.common.management] (MSC service thread 1-7) JBWS022052: Starting JBossWS 5.1.5.Final (Apache CXF 3.1.6) 
20:39:31,951 INFO  [org.jboss.as.connector.subsystems.datasources] (MSC service thread 1-8) WFLYJCA0001: Bound data source [java:jboss/datasources/ExampleDS]
20:39:32,148 INFO  [org.jboss.weld.deployer] (MSC service thread 1-5) WFLYWELD0003: Processing weld deployment jbosswildfly-1.0.war
20:39:32,206 INFO  [org.hibernate.validator.internal.util.Version] (MSC service thread 1-5) HV000001: Hibernate Validator 5.2.4.Final
20:39:32,440 INFO  [org.jboss.as.connector.deployers.jdbc] (MSC service thread 1-4) WFLYJCA0005: Deploying non-JDBC-compliant driver class com.mysql.jdbc.Driver (version 5.1)
20:39:32,441 INFO  [org.jboss.as.connector.deployers.jdbc] (MSC service thread 1-4) WFLYJCA0005: Deploying non-JDBC-compliant driver class com.mysql.fabric.jdbc.FabricMySQLDriver (version 5.1)
20:39:32,444 INFO  [org.jboss.as.connector.deployers.jdbc] (MSC service thread 1-4) WFLYJCA0005: Deploying non-JDBC-compliant driver class org.postgresql.Driver (version 9.2)
20:39:32,473 INFO  [org.jboss.weld.Version] (MSC service thread 1-4) WELD-000900: 2.3.5 (Final)
20:39:32,509 INFO  [org.jboss.as.connector.deployers.jdbc] (MSC service thread 1-5) WFLYJCA0018: Started Driver service with driver-name = jbosswildfly-1.0.war_com.mysql.jdbc.Driver_5_1
20:39:32,510 INFO  [org.jboss.as.connector.deployers.jdbc] (MSC service thread 1-6) WFLYJCA0018: Started Driver service with driver-name = jbosswildfly-1.0.war_com.mysql.fabric.jdbc.FabricMySQLDriver_5_1
20:39:32,512 INFO  [org.jboss.as.connector.deployers.jdbc] (MSC service thread 1-6) WFLYJCA0018: Started Driver service with driver-name = jbosswildfly-1.0.war_org.postgresql.Driver_9_2
20:39:33,458 INFO  [io.undertow.servlet] (ServerService Thread Pool -- 68) 1 Spring WebApplicationInitializers detected on classpath
20:39:33,532 INFO  [javax.enterprise.resource.webcontainer.jsf.config] (ServerService Thread Pool -- 68) Initializing Mojarra 2.2.13.SP1 20160303-1204 for context '/jbosswildfly-1.0'
20:39:34,739 INFO  [io.undertow.servlet] (ServerService Thread Pool -- 68) Initializing Spring FrameworkServlet 'rest'
20:39:34,741 INFO  [org.springframework.web.servlet.DispatcherServlet] (ServerService Thread Pool -- 68) FrameworkServlet 'rest': initialization started
20:39:34,745 INFO  [org.springframework.web.context.support.AnnotationConfigWebApplicationContext] (ServerService Thread Pool -- 68) Refreshing WebApplicationContext for namespace 'rest-servlet': startup date [Thu Jan 12 20:39:34 SAST 2017]; root of context hierarchy
20:39:34,778 INFO  [org.springframework.web.context.support.AnnotationConfigWebApplicationContext] (ServerService Thread Pool -- 68) Registering annotated classes: [class com.jobs.spring.configuration.AppConfig]
20:39:35,061 INFO  [org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor] (ServerService Thread Pool -- 68) JSR-330 'javax.inject.Inject' annotation found and supported for autowiring
20:39:35,171 INFO  [org.springframework.jdbc.datasource.DriverManagerDataSource] (ServerService Thread Pool -- 68) Loaded JDBC driver: com.mysql.jdbc.Driver
20:39:35,262 INFO  [org.hibernate.Version] (ServerService Thread Pool -- 68) HHH000412: Hibernate Core {5.2.1.Final}
20:39:35,264 INFO  [org.hibernate.cfg.Environment] (ServerService Thread Pool -- 68) HHH000206: hibernate.properties not found
20:39:35,265 INFO  [org.hibernate.cfg.Environment] (ServerService Thread Pool -- 68) HHH000021: Bytecode provider name : javassist
20:39:35,300 INFO  [org.hibernate.annotations.common.Version] (ServerService Thread Pool -- 68) HCANN000001: Hibernate Commons Annotations {5.0.1.Final}
20:39:35,588 WARN  [org.hibernate.engine.jdbc.env.internal.JdbcEnvironmentInitiator] (ServerService Thread Pool -- 68) HHH000342: Could not obtain connection to query metadata : Access denied for user 'admin'@'localhost' (using password: YES)
20:39:35,596 INFO  [org.hibernate.dialect.Dialect] (ServerService Thread Pool -- 68) HHH000400: Using dialect: org.hibernate.dialect.MySQLDialect
20:39:35,606 INFO  [org.hibernate.engine.jdbc.env.internal.LobCreatorBuilderImpl] (ServerService Thread Pool -- 68) HHH000422: Disabling contextual LOB creation as connection was null
20:39:36,268 WARN  [org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor] (ServerService Thread Pool -- 68) Autowired annotation is not supported on static fields: private static final java.util.logging.Logger com.jobs.spring.service.EmailServiceImpl.logger
20:39:36,456 INFO  [org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerMapping] (ServerService Thread Pool -- 68) Mapped "{[/category/list],methods=[GET],produces=[application/json]}" onto public org.springframework.http.ResponseEntity<java.util.List<com.jobs.spring.domain.Category>> com.jobs.spring.controller.CategoryRESTService.findAllCategorys()
20:39:36,459 INFO  [org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerMapping] (ServerService Thread Pool -- 68) Mapped "{[/category/list/{id}],methods=[GET],produces=[application/json]}" onto public org.springframework.http.ResponseEntity<com.jobs.spring.domain.Category> com.jobs.spring.controller.CategoryRESTService.findCategoryById(java.lang.String)
20:39:36,461 INFO  [org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerMapping] (ServerService Thread Pool -- 68) Mapped "{[/email/password/{email}/{userName}],methods=[GET],produces=[application/json]}" onto public org.springframework.http.ResponseEntity<java.lang.String> com.jobs.spring.controller.EmailRESTService.requestPassword(java.lang.String,java.lang.String)
20:39:36,493 INFO  [org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerMapping] (ServerService Thread Pool -- 68) Mapped "{[/subcategory/list/{categoryId}],methods=[GET],produces=[application/json]}" onto public org.springframework.http.ResponseEntity<java.util.List<com.jobs.spring.domain.SubCategory>> com.jobs.spring.controller.SubCategoryRESTService.findAllCategorys(java.lang.String)
20:39:36,494 INFO  [org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerMapping] (ServerService Thread Pool -- 68) Mapped "{[/subcategory/list],methods=[GET],produces=[application/json]}" onto public org.springframework.http.ResponseEntity<java.util.List<com.jobs.spring.domain.SubCategory>> com.jobs.spring.controller.SubCategoryRESTService.findAllCategorys()
20:39:36,494 INFO  [org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerMapping] (ServerService Thread Pool -- 68) Mapped "{[/subcategory/{id}],methods=[GET],produces=[application/json]}" onto public org.springframework.http.ResponseEntity<com.jobs.spring.domain.SubCategory> com.jobs.spring.controller.SubCategoryRESTService.findCategoryById(java.lang.String)
20:39:36,778 INFO  [org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter] (ServerService Thread Pool -- 68) Looking for @ControllerAdvice: WebApplicationContext for namespace 'rest-servlet': startup date [Thu Jan 12 20:39:34 SAST 2017]; root of context hierarchy
20:39:36,881 INFO  [org.springframework.web.servlet.DispatcherServlet] (ServerService Thread Pool -- 68) FrameworkServlet 'rest': initialization completed in 2140 ms
20:39:36,882 INFO  [org.wildfly.extension.undertow] (ServerService Thread Pool -- 68) WFLYUT0021: Registered web context: /jbosswildfly-1.0
20:39:36,916 INFO  [org.jboss.as.server] (ServerService Thread Pool -- 34) WFLYSRV0010: Deployed "jbosswildfly-1.0.war" (runtime-name : "jbosswildfly-1.0.war")
20:39:37,006 INFO  [org.jboss.as] (Controller Boot Thread) WFLYSRV0060: Http management interface listening on http://127.0.0.1:9990/management
20:39:37,006 INFO  [org.jboss.as] (Controller Boot Thread) WFLYSRV0051: Admin console listening on http://127.0.0.1:9990
20:39:37,007 INFO  [org.jboss.as] (Controller Boot Thread) WFLYSRV0025: WildFly Full 10.1.0.Final (WildFly Core 2.2.0.Final) started in 27297ms - Started 953 of 1201 services (404 services are lazy, passive or on-demand)

However, If I try access one of the RESTful services, eg: 但是,如果我尝试访问RESTful服务之一,例如:

http://localhost:8080/jbosswildfly/category/list

I get: 我得到:

404 - Not Found 404-找不到

And

http://localhost:8080/jbosswildfly/

Also returns: 还返回:

404 - Not Found 404-找不到

So I guess something is wrong with the context root: jbosswildfly 所以我想上下文根有问题: jbosswildfly

The code is exactly the same as the Windows environment, so I would have expected the OSX environment to have worked. 该代码与Windows环境完全相同,因此我希望OSX环境能够正常工作。

I am not sure if there is a problem with my Wildfly Server or my Spring config, or something else. 我不确定我的Wildfly Server或Spring配置或其他问题是否存在。

WebInitializer.java WebInitializer.java

public class WebAppInitializer implements WebApplicationInitializer {

    @Override
    public void onStartup(ServletContext servletContext) throws ServletException {
        AnnotationConfigWebApplicationContext ctx = new AnnotationConfigWebApplicationContext();
        ctx.register(AppConfig.class);
        ctx.setServletContext(servletContext);
        Dynamic dynamic = servletContext.addServlet("rest", new DispatcherServlet(ctx));
        dynamic.addMapping("/*");
        dynamic.setLoadOnStartup(1);
    }
}

The onStartup method above does get invoked on start up. 上面的onStartup方法在启动时会被调用。

CategoryRESTService.java 类别RESTService.java

@CrossOrigin(origins = {"*"})
@RestController
@RequestMapping(CategoryRESTService.BASE_URI)
public class CategoryRESTService {

    public static final String BASE_URI = "/category";

    @Autowired
    private CategoryService categoryService;

    @RequestMapping(value = "/list", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE)
    public ResponseEntity<List<Category>> findAllCategorys() {
        List<Category> categories = categoryService.findAll();
        return new ResponseEntity<List<Category>>(categories, HttpStatus.OK);
    }

    @RequestMapping(value = "/list/{id}", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE)
    public ResponseEntity<Category> findCategoryById(@PathVariable String id) {
        Category category = categoryService.findById(id);
        return new ResponseEntity<Category>(category, HttpStatus.OK);
    }
}

The app also runs successfully on an OpenShift Server with a Wildfly 10 cartridge. 该应用程序还可以在带有Wildfly 10墨盒的OpenShift服务器上成功运行。

Any help appreciated. 任何帮助表示赞赏。

看来您应该通过以下方式访问:

http://localhost:8080/jbosswildfly-1.0/category/list

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 在 Jboss Wildfly 服务器上运行 spring boot app - Run spring boot app on Jboss Wildfly server JBoss Wildfly应用程序服务器无法连接到SQL Server - JBoss Wildfly application server not able to connect to SQL Server 如何在jboss服务器中部署spring mvc应用程序? - How to deploy spring mvc application in jboss server? 使用myeclipse和jboss服务器运行jsf应用程序 - run jsf application with myeclipse and jboss server 如何在Jboss应用服务器上运行EJB 3应用 - how to run EJB 3 app on Jboss application server 如何将一个应用程序的身份验证重新用于部署在其他服务器(Wildfly或Jboss)中的另一个应用程序? - How to re use authentication of one application to another application deployed in other server (Wildfly or Jboss)? 如何使用无 XML Spring web 应用程序设置 JBoss Wildfly 上下文根? - How to set JBoss Wildfly context root with XML-less Spring web application? WildFly或JBoss EAP 6.2上的Spring异常翻译器 - Spring Exception Translator on WildFly or JBoss EAP 6.2 无法使用JBoss AS或Wildfly运行Errai开发模式 - Cannot run Errai Dev Mode with JBoss AS or Wildfly 在单个VPS上运行IIS和jboss / glassfish / wildfly - Run IIS and jboss/glassfish/wildfly on a single VPS
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM