Déployer le fichier WAR sur Tomcat de Spring Boot et Angular App
J'ai créé une application de démarrage angulaire et à ressort et je souhaite la déployer sur le serveur tomcat. Pour cela, j'ai copié le projet angulaire dans le projet Spring Boot et j'ai également fourni pom.xml pour créer un fichier war. Après cela, j'ai déployé le fichier de guerre sur tomcat et il est démarré.Veuillez me dire ce que c'est
- href de base dans index.html de angulaire
- quel chemin de contexte dois-je fournir?
- Dois-je avoir besoin de fournir server.port dans application.properties?
Mise à jour J'obtiens une erreur 404
Erreurs de console
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
Structure du projet
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;
}
}
Mon application fonctionne bien, mais chaque fois que j'essaye de la déployer en tant que guerre contre Tomcat, je peux voir le frontend mais je ne peux pas me connecter au backend. Je suis nouveau dans le déploiement de guerre, toute aide est appréciée.
Réponses
Étape 1: Créer une version pour l'angulaire
D'après la structure de projet partagée, il semble que vous ayez à la fois le code backend et frontend aux mêmes emplacements. Le moyen idéal est de créer le build / artficates pour l'angulaire qui crée le dossier dist à l'intérieur de votre dictornar angulaire qui se compose de vos actifs d'interface utilisateur. Pour créer le même, vous pouvez appuyer sur les commandes suivantes en fonction de votre environnement et de vos configurations
ng build --configuration=<env>
ng build --prod
Étape 2: Intgrate UI avec Spring Boot
Ensuite, vous pouvez créer les noms de dossier statiques dans src / main / resources et coller les actifs de l'interface utilisateur (fichiers dans le dossier dist) dans ce dossier statique.
Étape 3: Configurations de déploiement
Étape 1: modifiez l'option d'emballage en war dans pom.xml
<packaging>war</packaging>
Étape 2: étend 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);
}
}
Étape 3: créer unfichier WAR
mvn clean install
Et on y va! Nous pouvons accéder aux terminaux à
http://localhost:8080/context-path/endpoint OR
http://localhost:8080/war-filename/endpoint
Nous pouvons également créer le profil pour warcomme ci-dessous
<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>
Cela pourrait être utile
Il est possible de tout regrouper en une seule guerre, mais je trouve plus pratique de ne pas mélanger différentes applications (guerre backend et contenu dist frontal) comme un désordre, où nous cherchons déjà tous les deux quelle partie répond et où.
Plus facile, beaucoup plus facile en fait, consiste à appliquer la configuration suivante:
<Host appBase="webapps"
autoDeploy="false" name="localhost" unpackWARs="true"
xmlNamespaceAware="false" xmlValidation="false">
...
<Context docBase="/home/stuff" path="/static" />
</Host>
où la Contentbalise indique où vit le front-end. Frontend sur angulaire, comme cela peut sembler brillant, est une page statique pour Tomcat comme un serveur. Le backend, qui est Java je suppose, a sûrement besoin activement d'un serveur et doit être servi de la guerre.
Avec la docBase donnée, le contenu dist est copié-collé manuellement dans le /home/stuffdossier et il est affiché sur http: // localhost: 8080 / static / path. Vous ne devriez pas avoir besoin de index.html après la barre oblique, mais si vous en avez besoin pour une raison quelconque, ajoutez-le simplement. Ces valeurs d'emplacement et de chemin de fichier sont configurables librement à votre guise. Il convient également de mentionner que d'autres parties de la configuration illustrent simplement l'emplacement dans le fichier de configuration.
Le fichier de configuration utilisé est le server.xmlfichier de Tomcat .
Les chemins des applications backend déployées sont visibles sur la console de gestion de Tomcat.
Sources:
[1] https://www.moreofless.co.uk/static-content-web-pages-images-tomcat-outside-war/
Toutes les étapes que vous avez faites, comme l'a dit Patel Romil, sont correctes. La seule erreur que vous faites est d'appeler l'api au frontend. N'ajoutez aucun chemin de contexte dans l'url comme vous l'avez ajouté dans application.properties.
Si votre fichier WAR est déployé sur le chemin, wabITSpringvotre URL sera comme ceci dans index.html
var cfgApiBaseUrl = "https://localhost:8080/wabITSpring/"
Votre application ne se soucie pas du chemin du contexte et n'y fera aucune référence. Si votre contrôleur définit un chemin de / products, Tomcat le servira sous / wabITSpring / products.
var cfgApiBaseUrl = "https://localhost:8080/wabITSpring/products"
Faites cela et votre application fonctionnera avec succès.