0

I am trying to package angular app and spring boot app in a single war file and deploy in tomcat.

I am able to generate war file successfully and all the generated angular files are present at the root of war file.

when i try to deploy the war file and access using war name i cant able to access the index.html but able to access the rest api endpoints.

Im using spring-jersey instead of spring-web.

But when i try the same in a demo application which uses spring-jersey i am able to access the index.html using http://localhost:8080/war-name. and i see that there is a log which says o.s.b.a.w.s.WelcomePageHandlerMapping : Adding welcome page: ServletContext resource [/index.html] but i dont see this log in my main application.

<plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-war-plugin</artifactId>
                <version>3.3.2</version>
                <configuration>
                    <webResources>
                        <resource>
                            <directory>src/main/webapp/my-ui/dist/my-ui</directory>
                            <filtering>false</filtering>
                        </resource>
                    </webResources>
                    <warSourceExcludes>
                        my-ui/,
                        node_modules/**,
                        dist/,
                        node/
                    </warSourceExcludes>
                </configuration>
            </plugin>
            <plugin>
                <groupId>com.github.eirslett</groupId>
                <artifactId>frontend-maven-plugin</artifactId>
                <version>1.12.1</version>

                <configuration>
                    <!-- location of package.json, gulpfile.js etc -->
                    <workingDirectory>src/main/webapp/my-ui</workingDirectory>
                </configuration>

                <executions>
                    <execution>
                        <id>install node and npm</id>
                        <goals>
                            <goal>install-node-and-npm</goal>
                        </goals>

                        <phase>generate-resources</phase>
                        <configuration>
                            <nodeVersion>v16.16.0</nodeVersion>
                            <npmVersion>8.11.0</npmVersion>
                         
                        </configuration>
                    </execution>

                    <execution>
                        <id>npm install --production</id>
                        <goals>
                            <goal>npm</goal>
                        </goals>
                        <phase>generate-resources</phase>
                    </execution>

                    <execution>
                        <id>npm build</id>
                        <goals>
                            <goal>npm</goal>
                        </goals>
                        <configuration>
                            <arguments>run build</arguments>
                        </configuration>
                    </execution>

                </executions>
            </plugin>

            <plugin>
                <artifactId>maven-resources-plugin</artifactId>
                <executions>
                    <execution>
                        <id>copy-resources</id>
                        <phase>validate</phase>
                        <goals><goal>copy-resources</goal></goals>
                        <configuration>
                            <outputDirectory>${project.build.directory}/classes/static/</outputDirectory >
                            <resources>
                                <resource>
                                    <directory>src/main/webapp/my-ui/dist/my-ui</directory>
                                </resource>
                            </resources>
                        </configuration>
                    </execution>
                </executions>
            </plugin>

my main.java

    @SpringBootApplication
public class MyApplication extends SpringBootServletInitializer {
    public static void main(String[] args) {
        try {
            SpringApplication app = new SpringApplication(MyApplication.class);
            app.run(args);
        } catch(Throwable ex) {
            ex.printStackTrace();
        }
    }
    @Override
    protected SpringApplicationBuilder configure(SpringApplicationBuilder application) {
        return application.sources(MyApplication.class);
    }

I get below log when i access localhost:8080/war-name

2023-02-24T18:18:36.401+05:30  WARN 31619 --- [nio-9898-exec-1] o.s.web.servlet.PageNotFound             : No mapping for GET /war-name/
2023-02-24T18:18:36.402+05:30 ERROR 31619 --- [nio-9898-exec-1] o.s.b.w.servlet.support.ErrorPageFilter  : Cannot forward to error page for request [/index.html] as the response has already been committed. As a result, the response may have the wrong status code. If your application is running on WebSphere Application Server you may be able to resolve this problem by setting com.ibm.ws.webcontainer.invokeFlushAfterService to false

0 Answers0