Spring boot 및 Angular 앱의 Tomcat에 WAR 파일 배포
각도 및 봄 부팅 응용 프로그램을 만들었고 Tomcat 서버에 배포하고 싶습니다. 이를 위해 스프링 부트 프로젝트에서 각도 프로젝트를 복사하고 pom.xml을 제공하여 war 파일을 만듭니다. 그 후 바람둥이에 전쟁 파일을 배포하고 시작됩니다.
- 각도의 index.html에있는 기본 href
- 어떤 컨텍스트 경로를 제공해야합니까?
- application.properties에서 server.port를 제공해야합니까?
업데이트 404 오류가 발생합니다.
콘솔 오류
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
프로젝트 구조
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>
index.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>
application.properties
server.port=8080
server.servlet.context-path=/wabITSpring/onlineshopping
SecurityConfig.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;
}
}
내 응용 프로그램은 잘 작동하지만 바람둥이에 전쟁으로 배포하려고 할 때마다 프런트 엔드를 볼 수 있지만 백엔드에 연결할 수 없습니다. 나는 전쟁 배치에 익숙하지 않아 어떤 도움을 주시면 감사하겠습니다.
답변
1 단계 : Angular 용 빌드 만들기
공유 프로젝트 구조에서 동일한 위치에 백엔드와 프런트 엔드 코드가 모두있는 것 같습니다. 이상적인 방법은 UI 애셋으로 구성된 앵귤러 딕 터나 안에 dist 폴더를 만드는 앵귤러에 대한 빌드 / 아트 피 케이트를 만드는 것입니다. 똑같은 것을 만들려면 당신의 환경과 구성에 따라 다음 명령을 칠 수 있습니다.
ng build --configuration=<env>
ng build --prod
2 단계 : Spring Boot로 UI 통합
그런 다음 src / main / resources 내에 static 이라는 하나의 폴더 이름을 만들고이 정적 폴더 안에 UI 자산 (dist 폴더 내의 파일)을 붙여 넣을 수 있습니다.
3 단계 : 배포 구성
1 단계 : pom.xml 에서패킹 옵션을 war 로변경
<packaging>war</packaging>
2 단계 : SpringBootServletInitializer 확장
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);
}
}
3 단계 : WAR 파일생성
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>
도움이 될 수 있습니다
https://stackoverflow.com/q/60538846/10961238
모든 것을 하나의 전쟁에 묶을 수는 있지만 서로 다른 응용 프로그램 (백엔드 전쟁 및 프런트 엔드 콘텐츠)을 하나의 엉망으로 혼합하지 않는 것이 더 편리하다고 생각합니다.
실제로 더 쉽고, 훨씬 더 쉬운 것은 다음 구성을 적용하는 것입니다.
<Host appBase="webapps"
autoDeploy="false" name="localhost" unpackWARs="true"
xmlNamespaceAware="false" xmlValidation="false">
...
<Context docBase="/home/stuff" path="/static" />
</Host>
를 Where Content태그가 말하고 프론트 엔드가 사는 곳. 각도의 프론트 엔드, 얼마나 반짝 거리는지는 서버와 같은 Tomcat의 정적 페이지입니다. 내가 생각하는 자바 인 백엔드는 확실히 서버가 적극적으로 필요하며 전쟁에서 서비스를 받아야합니다.
주어진 docBase를 사용하면 dist 내용은 수동으로 /home/stuff폴더에 복사하여 붙여넣고 http : // localhost : 8080 / static / 경로에 표시됩니다. 슬래시 뒤에 index.html이 필요하지 않지만 어떤 이유로 필요한 경우 추가하십시오. 이러한 파일 위치 및 경로 값은 원하는대로 자유롭게 구성 할 수 있습니다. 또한 config의 다른 부분은 config 파일의 위치를 설명한다는 점도 언급 할 가치가 있습니다.
사용 된 구성 파일은 Tomcat의 server.xml파일입니다.
배포되는 백엔드 앱의 경로는 Tomcat의 관리 콘솔에서 볼 수 있습니다.
출처 :
[1] https://www.moreofless.co.uk/static-content-web-pages-images-tomcat-outside-war/
Patel Romil이 말한대로 수행 한 모든 단계가 옳습니다. 실수는 프론트 엔드에서 API를 호출하는 것뿐입니다. application.properties에 추가 한대로 url에 컨텍스트 경로를 추가하지 마십시오.
WAR 파일이 경로에 배포 된 경우 wabITSpringURL은 index.html에서 다음과 같습니다.
var cfgApiBaseUrl = "https://localhost:8080/wabITSpring/"
앱은 컨텍스트 경로를 신경 쓰지 않으며 이에 대한 참조도 없습니다. 컨트롤러가 / products의 경로를 정의하면 Tomcat은 / wabITSpring / products에서이를 제공합니다.
var cfgApiBaseUrl = "https://localhost:8080/wabITSpring/products"
이렇게하면 응용 프로그램이 성공적으로 실행됩니다.