ecplise SpringCould搭建过程---创建SpringCould父工程

妖狐艹你老母 2023-02-11 15:29 167阅读 0赞

1.创建maven项目

watermark_type_ZmFuZ3poZW5naGVpdGk_shadow_10_text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L2RhdG91bmlhbzE_size_16_color_FFFFFF_t_70

2.

watermark_type_ZmFuZ3poZW5naGVpdGk_shadow_10_text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L2RhdG91bmlhbzE_size_16_color_FFFFFF_t_70 1

  1. watermark_type_ZmFuZ3poZW5naGVpdGk_shadow_10_text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L2RhdG91bmlhbzE_size_16_color_FFFFFF_t_70 2

点击finish 项目创建完成,这个是一个父工程,

工程中目录:

  1. Springcould
  2. |\_\_\_\_\_src
  3. |\_\_\_\_\_site
  4. |\_\_\_\_pom.xml

其他的我们不用管,只看pom.xml文件:

  1. <project xmlns="http://maven.apache.org/POM/4.0.0"
  2. xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  3. xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
  4. <modelVersion>4.0.0</modelVersion>
  5. <groupId>com.could</groupId>
  6. <artifactId>ShopClould</artifactId>
  7. <version>1.0</version>
  8. <packaging>pom</packaging>
  9. <parent>
  10. <groupId>org.springframework.boot</groupId>
  11. <artifactId>spring-boot-starter-parent</artifactId>
  12. <version>2.0.7.RELEASE</version>
  13. </parent>
  14. <dependencyManagement>
  15. <dependencies>
  16. <dependency>
  17. <groupId>org.springframework.cloud</groupId>
  18. <artifactId>spring-cloud-dependencies</artifactId>
  19. <version>Finchley.SR2</version>
  20. <type>pom</type>
  21. <scope>import</scope>
  22. </dependency>
  23. <dependency>
  24. <groupId>org.springframework.cloud</groupId>
  25. <artifactId>spring-cloud-starter-netflix-eureka-server</artifactId>
  26. <version>1.4.7.RELEASE</version>
  27. </dependency>
  28. <dependency>
  29. <groupId>javax.persistence</groupId>
  30. <artifactId>persistence-api</artifactId>
  31. <version>1.0</version>
  32. </dependency>
  33. <dependency>
  34. <groupId>commons-logging</groupId>
  35. <artifactId>commons-logging</artifactId>
  36. <version>1.2</version>
  37. </dependency>
  38. <!--数据连接池管理 -->
  39. <!-- <dependency> <groupId>com.alibaba</groupId> <artifactId>druid</artifactId>
  40. <version>1.1.10</version> </dependency> -->
  41. <dependency>
  42. <groupId>com.alibaba</groupId>
  43. <artifactId>druid-spring-boot-starter</artifactId>
  44. <version>1.1.10</version>
  45. </dependency>
  46. <!-- https://mvnrepository.com/artifact/org.mybatis.spring.boot/mybatis-spring-boot-starter -->
  47. <dependency>
  48. <groupId>org.mybatis.spring.boot</groupId>
  49. <artifactId>mybatis-spring-boot-starter</artifactId>
  50. <version>1.3.2</version>
  51. </dependency>
  52. <!-- https://mvnrepository.com/artifact/mysql/mysql-connector-java -->
  53. <dependency>
  54. <groupId>mysql</groupId>
  55. <artifactId>mysql-connector-java</artifactId>
  56. <version>6.0.6</version>
  57. </dependency>
  58. <dependency>
  59. <groupId>log4j</groupId>
  60. <artifactId>log4j</artifactId>
  61. <version>1.2.17</version>
  62. </dependency>
  63. </dependencies>
  64. </dependencyManagement>
  65. <build>
  66. <finalName>spring-root</finalName>
  67. <plugins>
  68. <plugin>
  69. <groupId>org.springframework.boot</groupId>
  70. <artifactId>spring-boot-maven-plugin</artifactId>
  71. <executions>
  72. <execution>
  73. <goals>
  74. <goal>repackage</goal>
  75. </goals>
  76. </execution>
  77. </executions>
  78. </plugin>
  79. <plugin>
  80. <groupId>org.apache.maven.plugins</groupId>
  81. <artifactId>maven-compiler-plugin</artifactId>
  82. <configuration>
  83. <encoding>utf-8</encoding>
  84. <source>1.8</source>
  85. <target>1.8</target>
  86. </configuration>
  87. </plugin>
  88. </plugins>
  89. </build>
  90. </project>

这样我们就把整个父工程创建好了

之后我们需要的是一点点的去创建子工程

  1. 这个地方为了跟时代接轨我们创建的三个子项目 分别是:
  2. 注册中心: shop-eureka
  3. 配置中心:shop-config
  4. 用户管理中心:shop-user-service

首先来看配置中心:

watermark_type_ZmFuZ3poZW5naGVpdGk_shadow_10_text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L2RhdG91bmlhbzE_size_16_color_FFFFFF_t_70 3

直接点击finish:

watermark_type_ZmFuZ3poZW5naGVpdGk_shadow_10_text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L2RhdG91bmlhbzE_size_16_color_FFFFFF_t_70 4

watermark_type_ZmFuZ3poZW5naGVpdGk_shadow_10_text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L2RhdG91bmlhbzE_size_16_color_FFFFFF_t_70 5

我们首先来看配置:

注册中心

  1. <project xmlns="http://maven.apache.org/POM/4.0.0"
  2. xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  3. xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
  4. <modelVersion>4.0.0</modelVersion>
  5. <parent>
  6. <groupId>com.could</groupId>
  7. <artifactId>ShopClould</artifactId>
  8. <version>1.0</version>
  9. </parent>
  10. <artifactId>shop-eureka</artifactId>
  11. <!-- 添加注册中心依赖的包文件 -->
  12. <dependencies>
  13. <dependency>
  14. <groupId>org.springframework.cloud</groupId>
  15. <artifactId>spring-cloud-starter-netflix-eureka-server</artifactId>
  16. </dependency>
  17. <dependency>
  18. <groupId>org.springframework.boot</groupId>
  19. <artifactId>spring-boot-starter-security</artifactId>
  20. </dependency>
  21. </dependencies>
  22. <build>
  23. <finalName>shop-eureka</finalName>
  24. <plugins>
  25. <plugin>
  26. <groupId>org.springframework.boot</groupId>
  27. <artifactId>spring-boot-maven-plugin</artifactId>
  28. </plugin>
  29. </plugins>
  30. </build>
  31. </project>

application.yml

  1. server:
  2. port: 8001
  3. spring:
  4. security:
  5. basic:
  6. enable: true
  7. user:
  8. name: admin
  9. password: wdgcould
  10. eureka:
  11. instance:
  12. hostname: localhost
  13. client:
  14. register-with-eureka: false
  15. fetch-registry: false
  16. service-url:
  17. defaultZone: http://${spring.security.user.name}:${spring.security.user.password}@${eureka.instance.hostname}:${server.port}/eureka/

主函数:

  1. package com;
  2. import org.springframework.boot.SpringApplication;
  3. import org.springframework.boot.autoconfigure.SpringBootApplication;
  4. import org.springframework.cloud.netflix.eureka.server.EnableEurekaServer;
  5. @SpringBootApplication // spring-boot 启动注解
  6. @EnableEurekaServer // spring-cloud 服务注解
  7. public class RegisterMain {
  8. public static void main(String[] args) {
  9. SpringApplication.run(RegisterMain.class, args);
  10. }
  11. }

druid

  1. package com.config;
  2. import org.springframework.security.config.annotation.web.builders.HttpSecurity;
  3. import org.springframework.security.config.annotation.web.configuration.EnableWebSecurity;
  4. import org.springframework.security.config.annotation.web.configuration.WebSecurityConfigurerAdapter;
  5. @EnableWebSecurity
  6. class WebSecurityConfig extends WebSecurityConfigurerAdapter {
  7. @Override
  8. protected void configure(HttpSecurity http) throws Exception {
  9. http.csrf().ignoringAntMatchers("/eureka/**");
  10. super.configure(http);
  11. }
  12. }

发表评论

表情:
评论列表 (有 0 条评论,167人围观)

还没有评论,来说两句吧...

相关阅读