(八)Java springboot B2B2C o2o多用户商城 springcloud架构 - commonservice-eureka 项目构建过程...

我们针对于HongHu cloud的eureka项目做以下构建,整个构建的过程很简单,我会将每一步都构建过程记录下来,希望可以帮助到大家:

1. 创建一个名为particle-common-eureka的maven项目,继承particle-commonservice,具体的pom.xml配置文件如下:

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
	xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
	<modelVersion>4.0.0</modelVersion>

	<parent>
		<groupId>com.ml.honghu</groupId>
		<artifactId>particle-commonservice</artifactId>
		<version>0.0.1-SNAPSHOT</version>
	</parent>

	<artifactId>particle-commonservice-eureka</artifactId>
	<packaging>jar</packaging>

	<name>particle-commonservice-eureka</name>
	<description>particle-commonservice project for Spring Boot</description>

	<dependencies>
		<dependency>
			<groupId>org.springframework.cloud</groupId>
			<artifactId>spring-cloud-starter-eureka-server</artifactId>
		</dependency>
		<dependency>
			<groupId>org.springframework.boot</groupId>
			<artifactId>spring-boot-starter-security</artifactId>
		</dependency>
		<dependency>
			<groupId>org.springframework.boot</groupId>
			<artifactId>spring-boot-devtools</artifactId>
		</dependency>
		
		<dependency>
			<groupId>org.springframework.boot</groupId>
			<artifactId>spring-boot-starter-test</artifactId>
			<scope>test</scope>
		</dependency>

	</dependencies>

	<build>
		<plugins>
			<plugin>
				<groupId>org.springframework.boot</groupId>
				<artifactId>spring-boot-maven-plugin</artifactId>
				<executions>
					<execution>
						<id>1</id>
						<goals>
							<goal>repackage</goal>
						</goals>
					</execution>
	                <execution>
	                	<id>2</id>
	                    <goals>
	                        <goal>build-info</goal>
	                    </goals>
	                </execution>
				</executions>
				<configuration>
					<executable>true</executable>
				</configuration>
				
			</plugin>
		</plugins>
	</build>
</project>

2. 在启动类入口引用eureka的相关配置,代码如下:

package com.ml.honghu;

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.cloud.netflix.eureka.server.EnableEurekaServer;

@EnableEurekaServer
@SpringBootApplication
public class ServiceApplication {

	public static void main(String[] args) {
		SpringApplication.run(ServiceApplication.class, args);
	}
}

 3. 配置application.yml文件

# server (eureka 默认端口为:8761)
server:
  port: 8761

# spring
spring:
  application:
    name: particle-commonservice-erueka

# eureka
eureka: 
  client: 
    # 是否注册到eureka
    register-with-eureka: true
    # 是否从eureka获取注册信息
    fetch-registry: false
    availability-zones: 
      honghu: honghuZone
    service-url: 
      honghuZone: http://honghu:123456@localhost:8761/eureka/
      defaultZone: http://honghu:123456@localhost:8761/eureka/
  instance:
    prefer-ip-address: true
    hostname: localhost
    metadataMap:
      zone: honghuZone
      user: ${security.user.name}
      password: {security.user.password}
      
  # 指定环境
  environment: dev
  #指定数据中心
  datacenter: honghu
  # 关闭自我保护模式
  server: 
    enable-self-preservation: false
  #设置清理无效节点的时间间隔,默认60000,即是60s
    eviction-interval-timer-in-ms: 60000

# 服务认证
security: 
  basic: 
    enabled: true
  user: 
    name: honghu
    password: 123456

management:
  security:
    enabled: false

4. 增加项目的log机制和打包运行机制(后面我们会详细编写针对于Linux Centos下的打包部署机制)

5. 自此整个项目部署完成,通过手动方式进行Run As --> Spring Boot App,运行结果如下:

控制台运行结果:

 

访问控制台并登陆:

 

控制台运行效果:

需要源码可以加企鹅球球:一零三八七七四六二六     来源: java B2B2C 源码 Springcloud多租户电子商城系统 

从现在开始,我这边会将近期研发的spring cloud微服务云架构的搭建过程和精髓记录下来,帮助更多有兴趣研发spring cloud框架的朋友,大家来一起探讨spring cloud架构的搭建过程及如何运用于企业项目。

转载于:https://my.oschina.net/u/3026261/blog/3001613

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
Siemens Simatic IT使用Unity作为其依赖注入容器。要注入Simatic IT Common组件,您需要在Unity容器中注册它。 以下是一个示例代码片段,展示了如何将Simatic IT Common组件注册到Unity容器中: ```csharp using Siemens.SimaticIT.Common; // Create a new instance of the Unity container var container = new UnityContainer(); // Register the Simatic IT Common component container.RegisterType<ICommonService, CommonService>(); ``` 在这个示例中,`ICommonService`是Simatic IT Common组件的接口,`CommonService`是Simatic IT Common组件的实现类。通过调用`UnityContainer.RegisterType`方法,将`CommonService`注册到`ICommonService`接口上,从而实现依赖注入。 一旦您成功注册了Simatic IT Common组件,您就可以在其他类中使用它了。例如,您可以在以下类中注入Simatic IT Common组件: ```csharp public class MyService { private readonly ICommonService _commonService; public MyService(ICommonService commonService) { _commonService = commonService; } public void DoSomething() { // Use the Simatic IT Common component _commonService.LogInfo("Doing something..."); } } ``` 在这个示例中,`MyService`类具有一个构造函数,该构造函数接受一个`ICommonService`参数。当您创建`MyService`类的实例时,Unity容器将自动注入一个`CommonService`实例作为`ICommonService`参数,并将其传递给构造函数。这意味着您可以在`MyService`类中使用Simatic IT Common组件的功能。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值