HuimvAdminApplication.java 2.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. package com.huimv.admin;
  2. import org.apache.catalina.Context;
  3. import org.apache.catalina.connector.Connector;
  4. import org.apache.tomcat.util.descriptor.web.SecurityCollection;
  5. import org.apache.tomcat.util.descriptor.web.SecurityConstraint;
  6. import org.apache.tomcat.util.http.LegacyCookieProcessor;
  7. import org.mybatis.spring.annotation.MapperScan;
  8. import org.springframework.boot.SpringApplication;
  9. import org.springframework.boot.autoconfigure.SpringBootApplication;
  10. import org.springframework.boot.web.embedded.tomcat.TomcatContextCustomizer;
  11. import org.springframework.boot.web.embedded.tomcat.TomcatServletWebServerFactory;
  12. import org.springframework.boot.web.server.WebServerFactoryCustomizer;
  13. import org.springframework.context.annotation.Bean;
  14. import org.springframework.scheduling.annotation.EnableScheduling;
  15. import org.springframework.web.client.RestTemplate;
  16. @SpringBootApplication
  17. @MapperScan("com.huimv.admin.mapper")
  18. @EnableScheduling
  19. //@EnableDiscoveryClient
  20. public class HuimvAdminApplication {
  21. public static void main(String[] args) {
  22. SpringApplication.run(HuimvAdminApplication.class, args);
  23. }
  24. @Bean
  25. public static RestTemplate getRestTemplate(){
  26. return new RestTemplate();
  27. }
  28. @Bean
  29. public WebServerFactoryCustomizer<TomcatServletWebServerFactory> cookieProcessorCustomizer() {
  30. return tomcatServletWebServerFactory -> tomcatServletWebServerFactory.addContextCustomizers((TomcatContextCustomizer) context -> {
  31. context.setCookieProcessor(new LegacyCookieProcessor());
  32. });
  33. }
  34. @Bean
  35. public TomcatServletWebServerFactory servletContainer() {
  36. TomcatServletWebServerFactory tomcat = new TomcatServletWebServerFactory() {
  37. @Override
  38. protected void postProcessContext(Context context) {
  39. SecurityConstraint constraint = new SecurityConstraint();
  40. constraint.setUserConstraint("CONFIDENTIAL");
  41. SecurityCollection collection = new SecurityCollection();
  42. collection.addPattern("/*");
  43. constraint.addCollection(collection);
  44. context.addConstraint(constraint);
  45. }
  46. };
  47. tomcat.addAdditionalTomcatConnectors(httpConnector());
  48. return tomcat;
  49. }
  50. @Bean
  51. public Connector httpConnector() {
  52. Connector connector = new Connector("org.apache.coyote.http11.Http11NioProtocol");
  53. connector.setScheme("http");
  54. //Connector监听的http的默认端口号
  55. connector.setPort(8010);
  56. connector.setSecure(false);
  57. //监听到http的端口号后转向到的https的端口号,也就是项目配置的port
  58. connector.setRedirectPort(8011);
  59. return connector;
  60. }
  61. }