在 Spring Boot 和 Angular 应用程序的 Tomcat 上部署 WAR 文件

2023-11-26

我创建了一个 Angular 和 Spring Boot 应用程序,我想将其部署在 Tomcat 服务器上。为此,我在 Spring Boot 项目中复制了一个 Angular 项目,并提供了pom.xml创建 WAR 文件。之后我将 WAR 文件部署到 Tomcat 上并启动。它是什么?

  1. 基本 href 位于索引.html角的
  2. 我应该提供什么上下文路径?
  3. 我是否需要在 application.properties 中提供 server.port?

我收到 404 错误:

Enter image description here

Enter image description here

控制台错误

org.springframework.security.web.session.SessionManagementFilter@af8f6da, org.springframework.security.web.access.ExceptionTranslationFilter@7551f180, org.springframework.security.web.access.intercept.FilterSecurityInterceptor@67dc6d01]
     2020-10-14 19:17:57.066  INFO 5176 --- [ost-startStop-1] o.s.d.r.w.RepositoryRestHandlerAdapter   : Looking for @ControllerAdvice: org.springframework.boot.web.servlet.context.AnnotationConfigServletWebServerApplicationContext@3472387b: startup date [Wed Oct 14 19:17:26 IST 2020]; root of context hierarchy
     2020-10-14 19:17:57.071  INFO 5176 --- [ost-startStop-1] o.s.d.r.w.RepositoryRestHandlerAdapter   : Detected @ModelAttribute methods in globalController
     2020-10-14 19:17:57.100  INFO 5176 --- [ost-startStop-1] o.s.d.r.w.RepositoryRestHandlerMapping   : Mapped "{[/ || ],methods=[OPTIONS],produces=[application/hal+json || application/json]}" onto public org.springframework.http.HttpEntity<?> org.springframework.data.rest.webmvc.RepositoryController.optionsForRepositories()
     2020-10-14 19:17:57.101  INFO 5176 --- [ost-startStop-1] o.s.d.r.w.RepositoryRestHandlerMapping   : Mapped "{[/ || ],methods=[HEAD],produces=[application/hal+json || application/json]}" onto public org.springframework.http.ResponseEntity<?> org.springframework.data.rest.webmvc.RepositoryController.headForRepositories()
     2020-10-14 19:17:57.102  INFO 5176 --- [ost-startStop-1] o.s.d.r.w.RepositoryRestHandlerMapping   : Mapped "{[/ || ],methods=[GET],produces=[application/hal+json || application/json]}" onto public org.springframework.http.HttpEntity<org.springframework.data.rest.webmvc.RepositoryLinksResource> org.springframework.data.rest.webmvc.RepositoryController.listRepositories()
     2020-10-14 19:17:57.104  INFO 5176 --- [ost-startStop-1] o.s.d.r.w.RepositoryRestHandlerMapping   : Mapped "{[/{repository}],methods=[GET],produces=[application/hal+json || application/json]}" onto public org.springframework.hateoas.Resources<?> org.springframework.data.rest.webmvc.RepositoryEntityController.getCollectionResource(org.springframework.data.rest.webmvc.RootResourceInformation,org.springframework.data.rest.webmvc.support.DefaultedPageable,org.springframework.data.domain.Sort,org.springframework.data.rest.webmvc.PersistentEntityResourceAssembler) throws org.springframework.data.rest.webmvc.ResourceNotFoundException,org.springframework.web.HttpRequestMethodNotSupportedException
     2020-10-14 19:17:57.105  INFO 5176 --- [ost-startStop-1] o.s.d.r.w.RepositoryRestHandlerMapping   : Mapped "{[/{repository}],methods=[HEAD],produces=[application/hal+json || application/json]}" onto public org.springframework.http.ResponseEntity<?> org.springframework.data.rest.webmvc.RepositoryEntityController.headCollectionResource(org.springframework.data.rest.webmvc.RootResourceInformation,org.springframework.data.rest.webmvc.support.DefaultedPageable) throws org.springframework.web.HttpRequestMethodNotSupportedException
     2020-10-14 19:17:57.106  INFO 5176 --- [ost-startStop-1] o.s.d.r.w.RepositoryRestHandlerMapping   : Mapped "{[/{repository}/{id}],methods=[DELETE],produces=[application/hal+json || application/json]}" onto public org.springframework.http.ResponseEntity<?> org.springframework.data.rest.webmvc.RepositoryEntityController.deleteItemResource(org.springframework.data.rest.webmvc.RootResourceInformation,java.io.Serializable,org.springframework.data.rest.webmvc.support.ETag) throws org.springframework.data.rest.webmvc.ResourceNotFoundException,org.springframework.web.HttpRequestMethodNotSupportedException
     2020-10-14 19:17:57.107  INFO 5176 --- [ost-startStop-1] o.s.d.r.w.RepositoryRestHandlerMapping   : Mapped "{[/{repository}/{id}],methods=[PATCH],produces=[application/hal+json || application/json]}" onto public org.springframework.http.ResponseEntity<org.springframework.hateoas.ResourceSupport> org.springframework.data.rest.webmvc.RepositoryEntityController.patchItemResource(org.springframework.data.rest.webmvc.RootResourceInformation,org.springframework.data.rest.webmvc.PersistentEntityResource,java.io.Serializable,org.springframework.data.rest.webmvc.PersistentEntityResourceAssembler,org.springframework.data.rest.webmvc.support.ETag,java.lang.String) throws org.springframework.web.HttpRequestMethodNotSupportedException,org.springframework.data.rest.webmvc.ResourceNotFoundException
     2020-10-14 19:17:57.108  INFO 5176 --- [ost-startStop-1] o.s.d.r.w.RepositoryRestHandlerMapping   : Mapped "{[/{repository}/{id}],methods=[OPTIONS],produces=[application/hal+json || application/json]}" onto public org.springframework.http.ResponseEntity<?> org.springframework.data.rest.webmvc.RepositoryEntityController.optionsForItemResource(org.springframework.data.rest.webmvc.RootResourceInformation)
     2020-10-14 19:17:57.109  INFO 5176 --- [ost-startStop-1] o.s.d.r.w.RepositoryRestHandlerMapping   : Mapped "{[/{repository}],methods=[OPTIONS],produces=[application/hal+json || application/json]}" onto public org.springframework.http.ResponseEntity<?> org.springframework.data.rest.webmvc.RepositoryEntityController.optionsForCollectionResource(org.springframework.data.rest.webmvc.RootResourceInformation)
     2020-10-14 19:17:57.120  INFO 5176 --- [ost-startStop-1] o.s.d.r.w.RepositoryRestHandlerMapping   : Mapped "{[/{repository}],methods=[POST],produces=[application/hal+json || application/json]}" onto public org.springframework.http.ResponseEntity<org.springframework.hateoas.ResourceSupport> org.springframework.data.rest.webmvc.RepositoryEntityController.postCollectionResource(org.springframework.data.rest.webmvc.RootResourceInformation,org.springframework.data.rest.webmvc.PersistentEntityResource,org.springframework.data.rest.webmvc.PersistentEntityResourceAssembler,java.lang.String) throws org.springframework.web.HttpRequestMethodNotSupportedException
     2020-10-14 19:17:57.124  INFO 5176 --- [ost-startStop-1] o.s.d.r.w.RepositoryRestHandlerMapping   : Mapped "{[/{repository}/{id}],methods=[HEAD],produces=[application/hal+json || application/json]}" onto public org.springframework.http.ResponseEntity<?> org.springframework.data.rest.webmvc.RepositoryEntityController.headForItemResource(org.springframework.data.rest.webmvc.RootResourceInformation,java.io.Serializable,org.springframework.data.rest.webmvc.PersistentEntityResourceAssembler) throws org.springframework.web.HttpRequestMethodNotSupportedException
     2020-10-14 19:17:57.125  INFO 5176 --- [ost-startStop-1] o.s.d.r.w.RepositoryRestHandlerMapping   : Mapped "{[/{repository}],methods=[GET],produces=[application/x-spring-data-compact+json || text/uri-list]}" onto public org.springframework.hateoas.Resources<?> org.springframework.data.rest.webmvc.RepositoryEntityController.getCollectionResourceCompact(org.springframework.data.rest.webmvc.RootResourceInformation,org.springframework.data.rest.webmvc.support.DefaultedPageable,org.springframework.data.domain.Sort,org.springframework.data.rest.webmvc.PersistentEntityResourceAssembler) throws org.springframework.data.rest.webmvc.ResourceNotFoundException,org.springframework.web.HttpRequestMethodNotSupportedException
     2020-10-14 19:17:57.127  INFO 5176 --- [ost-startStop-1] o.s.d.r.w.RepositoryRestHandlerMapping   : Mapped "{[/{repository}/{id}],methods=[PUT],produces=[application/hal+json || application/json]}" onto public org.springframework.http.ResponseEntity<? extends org.springframework.hateoas.ResourceSupport> org.springframework.data.rest.webmvc.RepositoryEntityController.putItemResource(org.springframework.data.rest.webmvc.RootResourceInformation,org.springframework.data.rest.webmvc.PersistentEntityResource,java.io.Serializable,org.springframework.data.rest.webmvc.PersistentEntityResourceAssembler,org.springframework.data.rest.webmvc.support.ETag,java.lang.String) throws org.springframework.web.HttpRequestMethodNotSupportedException
     2020-10-14 19:17:57.130  INFO 5176 --- [ost-startStop-1] o.s.d.r.w.RepositoryRestHandlerMapping   : Mapped "{[/{repository}/{id}],methods=[GET],produces=[application/hal+json || application/json]}" onto public org.springframework.http.ResponseEntity<org.springframework.hateoas.Resource<?>> org.springframework.data.rest.webmvc.RepositoryEntityController.getItemResource(org.springframework.data.rest.webmvc.RootResourceInformation,java.io.Serializable,org.springframework.data.rest.webmvc.PersistentEntityResourceAssembler,org.springframework.http.HttpHeaders) throws org.springframework.web.HttpRequestMethodNotSupportedException
     2020-10-14 19:17:57.137  INFO 5176 --- [ost-startStop-1] o.s.d.r.w.RepositoryRestHandlerMapping   : Mapped "{[/{repository}/{id}/{property}],methods=[GET],produces=[application/hal+json || application/json]}" onto public org.springframework.http.ResponseEntity<org.springframework.hateoas.ResourceSupport> org.springframework.data.rest.webmvc.RepositoryPropertyReferenceController.followPropertyReference(org.springframework.data.rest.webmvc.RootResourceInformation,java.io.Serializable,java.lang.String,org.springframework.data.rest.webmvc.PersistentEntityResourceAssembler) throws java.lang.Exception
     2020-10-14 19:17:57.138  INFO 5176 --- [ost-startStop-1] o.s.d.r.w.RepositoryRestHandlerMapping   : Mapped "{[/{repository}/{id}/{property}/{propertyId}],methods=[GET],produces=[application/hal+json || application/json]}" onto public org.springframework.http.ResponseEntity<org.springframework.hateoas.ResourceSupport> org.springframework.data.rest.webmvc.RepositoryPropertyReferenceController.followPropertyReference(org.springframework.data.rest.webmvc.RootResourceInformation,java.io.Serializable,java.lang.String,java.lang.String,org.springframework.data.rest.webmvc.PersistentEntityResourceAssembler) throws java.lang.Exception
     2020-10-14 19:17:57.139  INFO 5176 --- [ost-startStop-1] o.s.d.r.w.RepositoryRestHandlerMapping   : Mapped "{[/{repository}/{id}/{property}],methods=[GET],produces=[application/x-spring-data-compact+json || text/uri-list]}" onto public org.springframework.http.ResponseEntity<org.springframework.hateoas.ResourceSupport> org.springframework.data.rest.webmvc.RepositoryPropertyReferenceController.followPropertyReferenceCompact(org.springframework.data.rest.webmvc.RootResourceInformation,java.io.Serializable,java.lang.String,org.springframework.data.rest.webmvc.PersistentEntityResourceAssembler) throws java.lang.Exception
     2020-10-14 19:17:57.140  INFO 5176 --- [ost-startStop-1] o.s.d.r.w.RepositoryRestHandlerMapping   : Mapped "{[/{repository}/{id}/{property}],methods=[PATCH || PUT || POST],consumes=[application/json || application/x-spring-data-compact+json || text/uri-list],produces=[application/hal+json || application/json]}" onto public org.springframework.http.ResponseEntity<? extends org.springframework.hateoas.ResourceSupport> org.springframework.data.rest.webmvc.RepositoryPropertyReferenceController.createPropertyReference(org.springframework.data.rest.webmvc.RootResourceInformation,org.springframework.http.HttpMethod,org.springframework.hateoas.Resources<java.lang.Object>,java.io.Serializable,java.lang.String) throws java.lang.Exception
     2020-10-14 19:17:57.141  INFO 5176 --- [ost-startStop-1] o.s.d.r.w.RepositoryRestHandlerMapping   : Mapped "{[/{repository}/{id}/{property}/{propertyId}],methods=[DELETE],produces=[application/hal+json || application/json]}" onto public org.springframework.http.ResponseEntity<org.springframework.hateoas.ResourceSupport> org.springframework.data.rest.webmvc.RepositoryPropertyReferenceController.deletePropertyReferenceId(org.springframework.data.rest.webmvc.RootResourceInformation,java.io.Serializable,java.lang.String,java.lang.String) throws java.lang.Exception
     2020-10-14 19:17:57.142  INFO 5176 --- [ost-startStop-1] o.s.d.r.w.RepositoryRestHandlerMapping   : Mapped "{[/{repository}/{id}/{property}],methods=[DELETE],produces=[application/hal+json || application/json]}" onto public org.springframework.http.ResponseEntity<? extends org.springframework.hateoas.ResourceSupport> org.springframework.data.rest.webmvc.RepositoryPropertyReferenceController.deletePropertyReference(org.springframework.data.rest.webmvc.RootResourceInformation,java.io.Serializable,java.lang.String) throws java.lang.Exception
     2020-10-14 19:17:57.144  INFO 5176 --- [ost-startStop-1] o.s.d.r.w.RepositoryRestHandlerMapping   : Mapped "{[/{repository}/search],methods=[OPTIONS],produces=[application/hal+json || application/json]}" onto public org.springframework.http.HttpEntity<?> org.springframework.data.rest.webmvc.RepositorySearchController.optionsForSearches(org.springframework.data.rest.webmvc.RootResourceInformation)
     2020-10-14 19:17:57.148  INFO 5176 --- [ost-startStop-1] o.s.d.r.w.RepositoryRestHandlerMapping   : Mapped "{[/{repository}/search/{search}],methods=[GET],produces=[application/x-spring-data-compact+json]}" onto public org.springframework.hateoas.ResourceSupport org.springframework.data.rest.webmvc.RepositorySearchController.executeSearchCompact(org.springframework.data.rest.webmvc.RootResourceInformation,org.springframework.http.HttpHeaders,org.springframework.util.MultiValueMap<java.lang.String, java.lang.Object>,java.lang.String,java.lang.String,org.springframework.data.rest.webmvc.support.DefaultedPageable,org.springframework.data.domain.Sort,org.springframework.data.rest.webmvc.PersistentEntityResourceAssembler)
     2020-10-14 19:17:57.149  INFO 5176 --- [ost-startStop-1] o.s.d.r.w.RepositoryRestHandlerMapping   : Mapped "{[/{repository}/search],methods=[HEAD],produces=[application/hal+json || application/json]}" onto public org.springframework.http.HttpEntity<?> org.springframework.data.rest.webmvc.RepositorySearchController.headForSearches(org.springframework.data.rest.webmvc.RootResourceInformation)
     2020-10-14 19:17:57.151  INFO 5176 --- [ost-startStop-1] o.s.d.r.w.RepositoryRestHandlerMapping   : Mapped "{[/{repository}/search/{search}],methods=[GET],produces=[application/hal+json || application/json]}" onto public org.springframework.http.ResponseEntity<?> org.springframework.data.rest.webmvc.RepositorySearchController.executeSearch(org.springframework.data.rest.webmvc.RootResourceInformation,org.springframework.util.MultiValueMap<java.lang.String, java.lang.Object>,java.lang.String,org.springframework.data.rest.webmvc.support.DefaultedPageable,org.springframework.data.domain.Sort,org.springframework.data.rest.webmvc.PersistentEntityResourceAssembler,org.springframework.http.HttpHeaders)
     2020-10-14 19:17:57.152  INFO 5176 --- [ost-startStop-1] o.s.d.r.w.RepositoryRestHandlerMapping   : Mapped "{[/{repository}/search/{search}],methods=[OPTIONS],produces=[application/hal+json || application/json]}" onto public org.springframework.http.ResponseEntity<java.lang.Object> org.springframework.data.rest.webmvc.RepositorySearchController.optionsForSearch(org.springframework.data.rest.webmvc.RootResourceInformation,java.lang.String)
     2020-10-14 19:17:57.152  INFO 5176 --- [ost-startStop-1] o.s.d.r.w.RepositoryRestHandlerMapping   : Mapped "{[/{repository}/search],methods=[GET],produces=[application/hal+json || application/json]}" onto public org.springframework.data.rest.webmvc.RepositorySearchesResource org.springframework.data.rest.webmvc.RepositorySearchController.listSearches(org.springframework.data.rest.webmvc.RootResourceInformation)
     2020-10-14 19:17:57.153  INFO 5176 --- [ost-startStop-1] o.s.d.r.w.RepositoryRestHandlerMapping   : Mapped "{[/{repository}/search/{search}],methods=[HEAD],produces=[application/hal+json || application/json]}" onto public org.springframework.http.ResponseEntity<java.lang.Object> org.springframework.data.rest.webmvc.RepositorySearchController.headForSearch(org.springframework.data.rest.webmvc.RootResourceInformation,java.lang.String)
     2020-10-14 19:17:57.161  INFO 5176 --- [ost-startStop-1] o.s.d.r.w.BasePathAwareHandlerMapping    : Mapped "{[/profile],methods=[GET]}" onto org.springframework.http.HttpEntity<org.springframework.hateoas.ResourceSupport> org.springframework.data.rest.webmvc.ProfileController.listAllFormsOfMetadata()
     2020-10-14 19:17:57.162  INFO 5176 --- [ost-startStop-1] o.s.d.r.w.BasePathAwareHandlerMapping    : Mapped "{[/profile],methods=[OPTIONS]}" onto public org.springframework.http.HttpEntity<?> org.springframework.data.rest.webmvc.ProfileController.profileOptions()
     2020-10-14 19:17:57.163  INFO 5176 --- [ost-startStop-1] o.s.d.r.w.BasePathAwareHandlerMapping    : Mapped "{[/profile/{repository}],methods=[OPTIONS],produces=[application/alps+json]}" onto org.springframework.http.HttpEntity<?> org.springframework.data.rest.webmvc.alps.AlpsController.alpsOptions()
     2020-10-14 19:17:57.164  INFO 5176 --- [ost-startStop-1] o.s.d.r.w.BasePathAwareHandlerMapping    : Mapped "{[/profile/{repository}],methods=[GET],produces=[application/alps+json || */*]}" onto org.springframework.http.HttpEntity<org.springframework.data.rest.webmvc.RootResourceInformation> org.springframework.data.rest.webmvc.alps.AlpsController.descriptor(org.springframework.data.rest.webmvc.RootResourceInformation)
     2020-10-14 19:17:57.165  INFO 5176 --- [ost-startStop-1] o.s.d.r.w.BasePathAwareHandlerMapping    : Mapped "{[/profile/{repository}],methods=[GET],produces=[application/schema+json]}" onto public org.springframework.http.HttpEntity<org.springframework.data.rest.webmvc.json.JsonSchema> org.springframework.data.rest.webmvc.RepositorySchemaController.schema(org.springframework.data.rest.webmvc.RootResourceInformation)
     2020-10-14 19:17:57.424  INFO 5176 --- [ost-startStop-1] o.s.b.a.e.web.EndpointLinksResolver      : Exposing 2 endpoint(s) beneath base path '/actuator'
     2020-10-14 19:17:57.503  INFO 5176 --- [ost-startStop-1] s.b.a.e.w.s.WebMvcEndpointHandlerMapping : Mapped "{[/actuator/health],methods=[GET],produces=[application/vnd.spring-boot.actuator.v2+json || application/json]}" onto public java.lang.Object org.springframework.boot.actuate.endpoint.web.servlet.AbstractWebMvcEndpointHandlerMapping$OperationHandler.handle(javax.servlet.http.HttpServletRequest,java.util.Map<java.lang.String, java.lang.String>)
     2020-10-14 19:17:57.505  INFO 5176 --- [ost-startStop-1] s.b.a.e.w.s.WebMvcEndpointHandlerMapping : Mapped "{[/actuator/info],methods=[GET],produces=[application/vnd.spring-boot.actuator.v2+json || application/json]}" onto public java.lang.Object org.springframework.boot.actuate.endpoint.web.servlet.AbstractWebMvcEndpointHandlerMapping$OperationHandler.handle(javax.servlet.http.HttpServletRequest,java.util.Map<java.lang.String, java.lang.String>)
     2020-10-14 19:17:57.508  INFO 5176 --- [ost-startStop-1] s.b.a.e.w.s.WebMvcEndpointHandlerMapping : Mapped "{[/actuator],methods=[GET],produces=[application/vnd.spring-boot.actuator.v2+json || application/json]}" onto protected java.util.Map<java.lang.String, java.util.Map<java.lang.String, org.springframework.boot.actuate.endpoint.web.Link>> org.springframework.boot.actuate.endpoint.web.servlet.WebMvcEndpointHandlerMapping.links(javax.servlet.http.HttpServletRequest,javax.servlet.http.HttpServletResponse)
     2020-10-14 19:17:58.181  INFO 5176 --- [ost-startStop-1] o.s.j.e.a.AnnotationMBeanExporter        : Registering beans for JMX exposure on startup
     2020-10-14 19:17:58.376  INFO 5176 --- [ost-startStop-1] com.springboot.wabit.WabitApplication    : Started WabitApplication in 33.544 seconds (JVM running for 58.21)
     2020-10-14 19:17:58.556  INFO 5176 --- [           main] org.apache.catalina.startup.Catalina     : Server startup in 56058 ms
     2020-10-14 19:18:00.111  INFO 5176 --- [nio-8086-exec-2] o.a.c.c.C.[.[localhost].[/wabSpring]     : Initializing Spring FrameworkServlet 'dispatcherServlet'
     2020-10-14 19:18:00.111  INFO 5176 --- [nio-8086-exec-2] o.s.web.servlet.DispatcherServlet        : FrameworkServlet 'dispatcherServlet': initialization started
     2020-10-14 19:18:00.214  INFO 5176 --- [nio-8086-exec-2] o.s.web.servlet.DispatcherServlet        : FrameworkServlet 'dispatcherServlet': initialization completed in 103 ms
     request ===null

项目结构

Enter image description here

File pom.xml

<build>
    <finalName>wabITSpring</finalName>
        <plugins>
            <plugin>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-maven-plugin</artifactId>
            </plugin>
        </plugins>
        <pluginManagement>
            <plugins>
                <plugin>
                    <groupId>org.apache.maven.plugins</groupId>
                    <artifactId>maven-war-plugin</artifactId>
                    <version>${maven-war-plugin.version}</version>
                    <executions>
                        <execution>
                            <goals>
                                <goal>war</goal>
                            </goals>
                            <phase>package</phase>
                        </execution>
                    </executions>
                    <configuration>
                        <warSourceIncludes>WEB-INF/**,META-INF/**</warSourceIncludes>
                        <failOnMissingWebXml>false</failOnMissingWebXml>
                        <warSourceDirectory>target/classes/static/</warSourceDirectory>
                        <webResources>
                            <resource>
                                <directory>src/main/webapp</directory>
                                <includes>
                                    <include>WEB-INF/**</include>
                                </includes>
                            </resource>
                        </webResources>
                    </configuration>
                </plugin>
            </plugins>
        </pluginManagement>
    </build>

    <profiles>
        <profile>
            <id>war</id>
            <build>
                <plugins>
                    <plugin>
                        <groupId>org.apache.maven.plugins</groupId>
                        <artifactId>maven-war-plugin</artifactId>
                    </plugin>
                </plugins>
            </build>
        </profile>
    </profiles>

File 索引.html

<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>Spring Boot + Angular 8</title>
<base href="">
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="icon" type="image/x-icon" href="favicon.ico">
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/css/bootstrap.min.css" rel="stylesheet">
<link href="https://fonts.googleapis.com/css?family=Roboto:300,400,
500&display=swap" rel="stylesheet">
<link href="https://fonts.googleapis.com/icon?family=Material+Icons" rel="stylesheet">
<link href="https://fonts.googleapis.com/css2?family=Prompt:wght@300&display=swap" rel="stylesheet">
<script type="text/javascript">

    var cfgApiBaseUrl = "https://localhost:8080/wabITSpring/onlineshopping"

</script>
<link rel="stylesheet" href="styles.ca7355ed03bb6e9eec0a.css">
</head>
<body>

应用程序属性

server.port=8080
server.servlet.context-path=/wabITSpring/onlineshopping

安全配置.java

@Configuration
@EnableWebSecurity
@EnableGlobalMethodSecurity(prePostEnabled = true)
public class SecurityConfig extends WebSecurityConfigurerAdapter {

@Autowired
DataSource dataSource;
@Autowired
private CustomUserDetailService customUserDetailService;

@Override
public void configure(WebSecurity web) throws Exception {
    web.ignoring().antMatchers("/resources/**");
}

@Override
protected void configure(HttpSecurity http) throws Exception {
    http.cors().and().csrf().disable().authorizeRequests().
        antMatchers("/**").permitAll().antMatchers("/")
        .hasRole("anonymousUser").anyRequest().authenticated()
        .and().sessionManagement()
        .sessionCreationPolicy(SessionCreationPolicy.STATELESS).and()
        .exceptionHandling()
                    .accessDeniedPage("/access-denied").and()
                    .addFilter(new JWTAuthenticationFilter(authenticationManager()))
                    .addFilter(new JWTAuthorizationFilter(authenticationManager(),
         customUserDetailService));
    }
}

JWTAuthorizationFilter.java

public class JWTAuthorizationFilter extends BasicAuthenticationFilter {
    private final CustomUserDetailService customUserDetailService;

    public JWTAuthorizationFilter(AuthenticationManager authenticationManager, CustomUserDetailService customUserDetailService) {
        super(authenticationManager);
        this.customUserDetailService = customUserDetailService;
    }

    @Override
    protected void doFilterInternal(HttpServletRequest request,
                                    HttpServletResponse response,
                                    FilterChain chain) throws IOException, ServletException {

        String header = request.getHeader(HEADER_STRING);

        System.out.println("request ===" + request.getHeader("Authorization"));

        if (header == null || !header.startsWith(TOKEN_PREFIX)) {
            chain.doFilter(request, response);
            return;
        }
        UsernamePasswordAuthenticationToken authenticationToken = getAuthenticationToken(request);
        SecurityContextHolder.getContext().setAuthentication(authenticationToken);
        chain.doFilter(request, response);
        Authentication authentication = SecurityContextHolder.getContext().getAuthentication();
    }

    private UsernamePasswordAuthenticationToken getAuthenticationToken(HttpServletRequest request) {
        String token = request.getHeader(HEADER_STRING);
        if (token == null)
            return null;
        String username = Jwts.parser().setSigningKey(SECRET)
                .parseClaimsJws(token.replace(TOKEN_PREFIX, ""))
                .getBody()
                .getSubject();
        UserDetails userDetails = customUserDetailService.loadUserByUsername(username);
        Authentication authentication = SecurityContextHolder.getContext().getAuthentication();
                  return username != null ?
                new UsernamePasswordAuthenticationToken(userDetails, null, userDetails.getAuthorities()) : null;
    }
}

我的应用程序工作正常,但每当我尝试将其部署为 Tomcat 上的 WAR 文件时,我都可以看到前端,但无法连接到后端。


第 1 步:为 Angular 创建构建

从共享项目结构来看,后端和前端代码似乎都位于同一位置。理想的方法是为 Angular 创建 build/artefacts,它会在 Angular 目录中创建包含 UI 资产的目标文件夹。 要创建相同的内容,您可以根据您的环境和配置输入以下命令。

ng build --configuration=<env>
ng build --prod

第 2 步:将 UI 与 Spring Boot 集成

然后你可以创建一个文件夹名称static within src/主/资源并将 UI 资源(目标文件夹内的文件)粘贴到此静态文件夹中。

步骤 3:部署配置

Step 1:将包装选项更改为war在文件中pom.xml

<packaging>war</packaging>

Step 2:延伸SpringBootServlet初始化器

import org.springframework.boot.builder.SpringApplicationBuilder;
import org.springframework.boot.web.servlet.support.SpringBootServletInitializer;

/**
 * This is a helper Java class that provides an alternative to creating a {@code web.xml}.
 * This will be invoked only when the application is deployed to a Servlet container like Tomcat, JBoss etc.
 */
public class ApplicationWebXml extends SpringBootServletInitializer {

    @Override
    protected SpringApplicationBuilder configure(SpringApplicationBuilder application) {
        return application.sources(ApplicationApp.class);
    }
}

Step 3: Create WAR file

mvn clean install

我们开始吧!我们可以访问端点

http://localhost:8080/context-path/endpoint OR
http://localhost:8080/war-filename/endpoint

我们还可以创建配置文件war如下:

<properties>
    <maven-war-plugin.version>3.2.3</maven-war-plugin.version>
</properties>

     <build>
        <plugins>
            <plugin>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-maven-plugin</artifactId>
            </plugin>
        </plugins>
        <pluginManagement>
            <plugins>
                <plugin>
                    <groupId>org.apache.maven.plugins</groupId>
                    <artifactId>maven-war-plugin</artifactId>
                    <version>${maven-war-plugin.version}</version>
                    <executions>
                        <execution>
                            <goals>
                                <goal>war</goal>
                            </goals>
                            <phase>package</phase>
                        </execution>
                    </executions>
                    <configuration>
                        <warSourceIncludes>WEB-INF/**,META-INF/**</warSourceIncludes>
                        <failOnMissingWebXml>false</failOnMissingWebXml>
                        <warSourceDirectory>target/classes/static/</warSourceDirectory>
                        <webResources>
                            <resource>
                                <directory>src/main/webapp</directory>
                                <includes>
                                    <include>WEB-INF/**</include>
                                </includes>
                            </resource>
                        </webResources>
                    </configuration>
                </plugin>
            </plugins>
        </pluginManagement>
    </build>


    <profiles>
        <profile>
            <id>war</id>
            <build>
                <plugins>
                    <plugin>
                        <groupId>org.apache.maven.plugins</groupId>
                        <artifactId>maven-war-plugin</artifactId>
                    </plugin>
                </plugins>
            </build>
        </profile>
    </profiles>

将 WAR 部署到 Tomcat(Spring Boot + Angular)

本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

在 Spring Boot 和 Angular 应用程序的 Tomcat 上部署 WAR 文件 的相关文章

随机推荐

  • 创建 OpenID 登录小部件

    我需要一个 OpenID 登录小部件 例如 Stackoverflow 上的小部件或ID选择器 该服务已被终止 取而代之的是 RPXnow 这是一项商业服务 制作这些的最好方法是什么 是否有框架或示例实现 谷歌有一个项目叫谷歌身份工具包 G
  • 我们可以获得目录的修改时间和大小(即统计数据)吗?

    我们可以在 php 中获取目录的修改时间和大小 即统计信息 吗 如何 是的 您可以利用stat功能 stat stat path to directory echo Modification time stat mtime will sho
  • 从字符串中提取主题标签。

    如果我有这样的字符串 var comment Mmmm yummy donut at CZ 如何获取字符串变量中存在的哈希标签列表 我尝试使用 JavaScript split 方法 但我必须继续拆分从初始拆分字符串创建的所有字符串 有更简
  • 如何使用 MongoDB 聚合进行通用集合操作(​​并集、交集、差集)

    我遇到过一些特殊目的的集合运算实现 但没有遇到过一般情况 执行集合运算 特别是交集 并集 对称差 的一般情况是什么 在 where 或 map reduce 中使用 javascript 更容易弄清楚这一点 但我想知道如何在聚合中执行此操作
  • StringBuilder/StringBuffer 与“+”运算符

    我正在阅读 更好 更快 更轻的 Java 作者 Bruce Tate 和 Justin Gehtland 并且熟悉敏捷类型团队的可读性要求 例如 Robert Martin 在他的干净编码书中讨论的内容 在我现在所在的团队中 我被明确告知不
  • 如何通过 tweepy 将流式推文保存为 json?

    我已经通过在线课程学习 Python 几个月了 并且希望通过现实世界的迷你项目进一步学习 对于这个项目 我想从 Twitter Streaming API 收集推文并将其存储为 json 格式 尽管您可以选择只保存 status text
  • Laravel 4 中的自定义电子邮件标头

    我似乎无法在 Laravel 4 文档 电子邮件 API 中找到可以向电子邮件添加自定义标头的方法 例如 Mail send emails welcome data function message message gt to email
  • 为什么c++禁止void*的隐式转换?

    在C中 我们可以转换void 到任何其他指针 但C 禁止这样做 int a malloc 4 导致这个错误 invalid conversion from void to int fpermissive C 中是否存在潜在的危险 有c 的例
  • 启用 StrictMode 的 Crashlytics(检测全部)给出“检测到未标记的套接字”

    我尝试过添加Crashlytics到我的应用程序 它已经有StrictMode启用与detectAll 结果是Untagged socket detected use TrafficStats setThreadSocketTag to t
  • IE8 在重定向后打开新窗口时会丢失 cookie

    我使用的是 Internet Explorer 8 beta 2 客户端执行 POSThttp alpha foo 服务器响应重定向到http beta bar 客户端执行 GEThttp beta bar 服务器响应重定向到http be
  • 在 WPF 中对部分透明图像进行着色

    如何在不牺牲性能的情况下对 WPF 中的图像进行着色 使用 MVVM 纯粹的 XAML 解决方案将是理想的 因为修改代码中的位图会导致性能损失以及大量更改的图像 该图像不仅仅是由简单的形状组成 因此不可能使用路径 与 WinForms GD
  • MySQL 的扩展解决方案(复制、集群)

    At the startup我正在工作 我们现在正在考虑数据库的扩展解决方案 对于 MySQL 事情变得有些混乱 至少对我来说 它有MySQL集群 复制 and MySQL集群复制 从版本 5 1 6 开始 这是 MySQL 集群的异步版本
  • \frac{}{} 对我来说用 pylab 不起作用

    我对使用 python 尤其是 numpy 和 matplotlib 相当陌生 运行下面的代码 无需 frac 部分 产生错误 Normalized Distance in Chamber rac x L Expected end of t
  • 无法在 Chrome 中编辑 CSS STYLE 属性(变灰并被阻止)

    我遇到 以前没见过 一些奇怪的问题 当我输入一个网站时 有问题的网站是RunForGithub com 第一次 然后打开 Chrome Inspect 控制台 然后我可以动态修改 css 属性 但是 当我刷新页面 F5 时 我无法再修改它们
  • iPhone发出POST请求,处理cookie

    我希望有人能够阐明以下内容 我认为我正在朝着正确的方向前进 我想使用用户 密码组合登录我的服务器 然后我需要能够判断我是否正确登录 应该删除 cookie 如果是这种情况 我将发出另一个请求 感谢任何帮助 这是我正在使用的代码 NSHTTP
  • Key Vault 返回 401 和访问令牌(MSI PowerShell Function App)

    我正在尝试连接到Keyvault和我的Azure 函数 using 电源外壳 托管服务身份 MSI 已打开 并且在 Keyvault 中我授予了 MSI 获取 和 列表 访问策略 使用下面的脚本我成功获得了访问令牌 但是当我向 Keyvau
  • 我应该使用 CakePHP 2 还是 3 进行开发 [关闭]

    Closed 这个问题是基于意见的 目前不接受答案 我刚刚开始使用 CakePHP 开发一个软件即服务项目 我可以看到版本 3 仍处于测试阶段 并且我可以看到该项目需要 3 6 个月的时间 我的问题是我应该从版本 2 还是版本 3 beta
  • 如何将具有相同名称和模式但不同目录的文本文件导入数据库?

    我需要将多个具有相同名称和相同架构的txt文件导入到SQL Server 2008数据库中的同一个表中 我遇到的问题是它们都位于不同的目录中 TEST 201304 sample1 txt sample2 txt 201305 sample
  • RecyclerView - 网格布局管理器列的动画更改

    我想要动画化我的变化RecyclerViews GridLayoutManager 我默认在包含 3 列的网格中显示项目列表 用户可以选择显示更多或更少的列 我想要views in the RecyclerView移动 扩展到他们的新职位
  • 在 Spring Boot 和 Angular 应用程序的 Tomcat 上部署 WAR 文件

    我创建了一个 Angular 和 Spring Boot 应用程序 我想将其部署在 Tomcat 服务器上 为此 我在 Spring Boot 项目中复制了一个 Angular 项目 并提供了pom xml创建 WAR 文件 之后我将 WA