jboss eap 6.4 in maven access failed

时间:2017-12-06 07:49:44

标签: java spring eclipse maven jboss

我已经将war包中内置的maven项目部署到Jboss EAP 6.4并成功部署了WAR包。我已经创建了服务并在本地eclipse中使用spring-boot运行,我可以在浏览器中运行但是在Jboss eap中访问基于war包的URL时我遇到了问题。我成功运行jboss服务但无法运行URL。例如,我有使用url的方法GET服务:localhost:8080 / letter-printing-eap-generator / testing不能在jboss中运行,而是在部署之前在本地eclipse中运行。如何解决这个问题? maven项目中的任何配置xml?我只是添加了jboss插件。谢谢。我的代码:

我的pom.xml:

<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>
    <groupId>com.prudential.letter.printing</groupId>
    <artifactId>letter-printing-eap-generator</artifactId>
    <version>0.0.1-SNAPSHOT</version>

    <packaging>war</packaging>

    <name>LetterPrintingEapGenerator</name>

    <parent>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-parent</artifactId>
        <version>1.5.2.RELEASE</version>
    </parent>

    <properties>
        <java.version>1.8</java.version>
        <spring-cloud.version>1.2.2.RELEASE</spring-cloud.version>
        <swagger.version>2.6.1</swagger.version>
        <jboss.home>${env.JBOSS_HOME}</jboss.home>
        <config.server>http://10.170.49.103/configserver</config.server>
    </properties>

    <dependencies>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-web</artifactId>
        </dependency>
        <dependency>
            <groupId>com.fasterxml.jackson.dataformat</groupId>
            <artifactId>jackson-dataformat-xml</artifactId>
        </dependency>

        <!-- Spring Boot -->
        <dependency>
            <groupId>org.springframework.cloud</groupId>
            <artifactId>spring-cloud-starter-config</artifactId>
            <version>${spring-cloud.version}</version>
        </dependency>

        <!-- Swagger -->
        <dependency>
            <groupId>io.springfox</groupId>
            <artifactId>springfox-swagger2</artifactId>
            <version>${swagger.version}</version>
            <scope>compile</scope>
        </dependency>

        <dependency>
            <groupId>io.springfox</groupId>
            <artifactId>springfox-swagger-ui</artifactId>
            <version>${swagger.version}</version>
            <scope>compile</scope>
        </dependency>

        <dependency>
            <groupId>io.springfox</groupId>
            <artifactId>springfox-data-rest</artifactId>
            <version>${swagger.version}</version>
        </dependency>       

        <dependency>
            <groupId>org.webjars</groupId>
            <artifactId>bootstrap</artifactId>
            <version>3.3.5</version>
        </dependency>

    </dependencies>
    <build>
        <plugins>
            <plugin>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-maven-plugin</artifactId>
            </plugin>
            <!-- JBOSS maven plugin to simulate deployment to JBOSS -->
            <plugin>
                <groupId>org.jboss.as.plugins</groupId>
                <artifactId>jboss-as-maven-plugin</artifactId>
                <version>7.9.Final</version>
                <configuration>
                    <jbossHome>${jboss.home}</jbossHome>
                    <serverArgs>
                        <serverArg>-Dspring.profiles.active=${run.profiles}</serverArg>
                        <serverArg>-Dspring.cloud.config.uri=${config.server}</serverArg>
                    </serverArgs>
                </configuration>
            </plugin>           
        </plugins>
    </build>
</project>

SpringBootRestApiApp.java

@SpringBootApplication(scanBasePackages={"com.prudential.letter.printing"})
@Import({SpringDataRestConfiguration.class})
public class SpringBootRestApiApp {
    public static void main(String[] args) {
        SpringApplication.run(SpringBootRestApiApp.class, args);
    }
}

我的控制员:

@RestController
@RequestMapping(value="/")
public class TestingController {

    @GetMapping("testing")
    public String getTestingMethod(){
        return "Hello Testing";
    }

    @GetMapping("data")
    public Map<String, Object> getData(){
        Map<String, Object> map = new HashMap<String, Object>();

        map.put("status", "200");
        map.put("message", "ini messagenya");
        map.put("content", "mantap");

        return map;
    }
}

这是我的项目结构:

project structure

application.yml:

server:
  port: 8080
  contextPath: /letter-printing-eap-generator

1 个答案:

答案 0 :(得分:0)

在没有任何特定配置的情况下,JBoss EAP将在名称与WAR文件名匹配的上下文中提供对Web应用程序的访问。

因此,您的应用程序应该可以在以下位置访问:

http://localhost:8080/letter-printing-eap-generator-0.0.1-SNAPSHOT/testing

为了开发目的而更改此选项的一种常用方法是在pom.xml文件中包含finalName元素:

    <build>
        <finalName>${project.artifactId}</finalName>
        ...
    </build>

这将生成一个名为letter-printing-eap-generator.war的WAR文件,您尝试的原始URL应该可用。

或者,您可以将jboss-web.xml文件添加到包含context-root元素的部署(在WEB-INF目录中):

<jboss-web>
     <context-root>letter-printing-eap-generator</context-root>
</jboss-web>

您也可以使用JBoss CLI或Web控制台执行此操作。