有 Java 编程相关的问题?

你可以在下面搜索框中键入要查询的问题!

java Angular2和Spring boot将Angular2应用程序构建为war文件

我有一个angular2应用程序(MyNewApp)和Spring boot应用程序(MyNewAppROOT)来构建一个war文件,以便部署在tomcat服务器中。在MyNewAppROOT应用程序中,有一些代理控制器,如下所示

@Controller
public class ProxyController
{

    @RequestMapping(value = "/api/**", produces = "application/json;charset=UTF-8")
    @ResponseBody
    public String mirrorMyBoxAny( HttpMethod method, HttpServletRequest request, HttpServletResponse response )
    {
        return ProxyService.exchange( method, request, response );
    }

    public static void main(String args[])
    {

    }

}

另一个代理人

@RestController
public class MyNewAppController
{

    @RequestMapping(method = { RequestMethod.POST }, value = "my-dashboard/**", produces = "application/json")
    public String getStatistics( HttpMethod method, HttpServletRequest request, HttpServletResponse response )
    {
        //content
    }
}

pom。xml

<?xml version="1.0" encoding="UTF-8"?>
<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>it.my.app.web</groupId>
    <artifactId>MyNewApp</artifactId>
    <version>1.0.0</version>
    <packaging>war</packaging>

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

    <properties>
        <java.version>1.8</java.version>
        <war.name>ROOT</war.name>
        <war.path>${project.basedir}/target/ROOT.war</war.path>
        <deploy.module.name>MyNewApp</deploy.module.name>
        <app.localrepository.common>http://artifacts.my.net/artifactory/project-libs</app.localrepository.common>
    </properties>

    <dependencies>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-web</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-test</artifactId>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>com.jayway.jsonpath</groupId>
            <artifactId>json-path</artifactId>
            <scope>test</scope>
        </dependency>
    </dependencies>

    <pluginRepositories>
        <pluginRepository>
            <id>central</id>
            <url>https://repo1.maven.org/maven2</url>
            <releases>
                <enabled>true</enabled>
            </releases>
        </pluginRepository>
        <pluginRepository>
            <id>my-repo</id>
            <name>my Intranet Maven Repository</name>
            <url>${app.localrepository.common}</url>
        </pluginRepository>
        <pluginRepository>
            <id>spring-releases</id>
            <url>https://repo.spring.io/libs-release</url>
        </pluginRepository>
    </pluginRepositories>

    <build>
        <finalName>ROOT</finalName>
        <plugins>
            <plugin>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-maven-plugin</artifactId>
                <!--Build Info Goal-->
                <executions>
                    <execution>
                        <goals>
                            <goal>build-info</goal>
                        </goals>
                        <configuration>
                            <additionalProperties>
                                <number>${buildNumber}</number>
                            </additionalProperties>
                            <outputFile>${basedir}\src\main\resources\properties\build-info.properties</outputFile>
                        </configuration>
                    </execution>
                </executions>
            </plugin>
            <plugin>
                <artifactId>maven-resources-plugin</artifactId>
                <version>3.0.1</version>
                <executions>
                    <execution>
                        <id>copy-resources</id>
                        <!-- here the phase you need -->
                        <phase>validate</phase>
                        <goals>
                            <goal>copy-resources</goal>
                        </goals>
                        <configuration>
                            <outputDirectory>target/ROOT</outputDirectory>
                            <resources>
                                <resource>
                                    <directory>../MyNewApp/dist</directory>
                                    <filtering>false</filtering>
                                </resource>
                                <resource>
                                    <directory>../MyNewAppUI/src/app/styles/</directory>
                                    <filtering>false</filtering>
                                </resource>
                            </resources>
                        </configuration>
                    </execution>
                </executions>
            </plugin>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-deploy-plugin</artifactId>
                <version>2.8.2</version>
                <configuration>
                    <skip>true</skip>
                </configuration>
            </plugin>
            <plugin>
                <artifactId>maven-antrun-plugin</artifactId>
                <version>1.7</version>
                <executions>
                    <execution>
                        <phase>deploy</phase>
                        <goals>
                            <goal>run</goal>
                        </goals>
                        <configuration>
                            <target>
                                <!--Use ant-contrib for Task IF -->
                                <taskdef resource="net/sf/antcontrib/antcontrib.properties">
                                    <classpath>
                                        <pathelement location="${ant-contrib:ant-contrib:jar}"/>
                                    </classpath>
                                </taskdef>

                                <!--Deploy the war file created by the profile -->
                                <!--deploy.module.name parameter is used to define the module to
                                    be uploaded when the -->
                                <!--war file name is differ from the module name -->
                                <echo>Jenkins Server ref : ${server}</echo>
                                <echo>deploy.module.name : ${deploy.module.name}</echo>
                                <echo>war.name : ${war.name}</echo>
                                <echo>war.path : ${war.path}</echo>
                                <if>
                                    <or>
                                        <and>
                                            <isset property="deploy.module.name"/>
                                            <equals arg1="${project.name}" arg2="${deploy.module.name}"/>
                                        </and>
                                    </or>
                                    <then>
                                        <property name="cganthelper.path" value="${it.my:CGAntHelper:jar}"/>
                                        <taskdef name="deployTask" classname="it.my.ant.Deploy"
                                                 classpath="${cganthelper.path}"/>
                                        <echo>war.path : ${war.path}</echo>
                                        <deployTask serverRef="${server}" type="dist"
                                                    file="${war.path}" autodeploy="${deploy.auto}"/>
                                    </then>
                                </if>
                            </target>
                        </configuration>
                    </execution>
                </executions>
                <dependencies>
                    <dependency>
                        <groupId>ant-contrib</groupId>
                        <artifactId>ant-contrib</artifactId>
                        <version>1.0b3</version>
                    </dependency>
                </dependencies>
            </plugin>
            <!--Build Number Plugin-->
            <plugin>
                <groupId>org.codehaus.mojo</groupId>
                <artifactId>buildnumber-maven-plugin</artifactId>
                <version>1.4</version>
                <executions>
                    <execution>
                        <id>ex1</id>
                        <phase>validate</phase>
                        <goals>
                            <goal>create</goal>
                        </goals>
                    </execution>
                </executions>
                <configuration>
                    <revisionOnScmFailure>unknown</revisionOnScmFailure>
                    <format>{0}</format>
                    <items>
                        <item>buildNumber</item>
                    </items>
                    <doCheck>false</doCheck>
                    <doUpdate>false</doUpdate>
                </configuration>
            </plugin>
        </plugins>
    </build>

    <scm>
        <connection>scm:svn:http://none</connection>
        <developerConnection>scm:svn:https://none</developerConnection>
        <url>scm:svn:https://none</url>
    </scm>

    <repositories>
        <repository>
            <id>spring-releases</id>
            <url>https://repo.spring.io/libs-release</url>
        </repository>

        <!--<repository>-->
            <!--<id>spring-releases</id>-->
            <!--<url>https://repo.maven.apache.org/maven2/</url>-->
        <!--</repository>-->
    </repositories>

    <distributionManagement>
        <repository>

        </repository>
    </distributionManagement>

</project>

代理。配置。json

{
  "/api": {
    "target": "http://111.111.0.1:3003",
    "secure": false,
    "pathRewrite": {
      "^/api": ""
    },
    "changeOrigin": true
  }
}

首先,我运行命令ngbuild--prod来创建dist文件夹。之后,进行一次干净的安装,这样就可以创建ROOT。战争档案

但我的要求是创建一个不同名称的war文件,比如我的应用程序。战争不是根。战争

如何更改pom文件以及如何构建MyNewApp angular2应用程序以使用它

如有任何建议,我们将不胜感激

谢谢!


共 (0) 个答案