第一次提交
This commit is contained in:
commit
c03020069e
|
@ -0,0 +1 @@
|
|||
* text=auto eol=lf
|
|
@ -0,0 +1,28 @@
|
|||
# Build and Release Folders
|
||||
target/
|
||||
|
||||
# Eclipse
|
||||
.settings/
|
||||
*.classpath
|
||||
*.project
|
||||
*.factorypath
|
||||
|
||||
# IntelliJ IDEA
|
||||
.idea
|
||||
*.iml
|
||||
|
||||
# vscode
|
||||
.vscode
|
||||
|
||||
# JRebel
|
||||
rebel.xml
|
||||
|
||||
# macOS
|
||||
.DS_Store
|
||||
|
||||
# svn
|
||||
.svn/
|
||||
|
||||
# vue
|
||||
kernel-standard/
|
||||
node_modules/
|
|
@ -0,0 +1,59 @@
|
|||
version: '3.1'
|
||||
|
||||
services:
|
||||
db:
|
||||
image: mysql:latest
|
||||
container_name: mysql01
|
||||
restart: always
|
||||
ports:
|
||||
- "3309:3306"
|
||||
command: --default-authentication-plugin=mysql_native_password
|
||||
environment:
|
||||
MYSQL_ROOT_PASSWORD: 'Y9i-83204585'
|
||||
MYSQL_DATABASE: 'demo01'
|
||||
volumes:
|
||||
- d:/docker-data/mysql:/var/lib/mysql
|
||||
|
||||
redis:
|
||||
image: redis:latest
|
||||
container_name: redis01
|
||||
restart: always
|
||||
ports:
|
||||
- "7379:6379"
|
||||
command: redis-server --requirepass "y9i-83204585"
|
||||
volumes:
|
||||
- d:/docker-data/redis:/data
|
||||
|
||||
elasticsearch:
|
||||
image: elasticsearch:8.8.1
|
||||
container_name: elastic01
|
||||
restart: always
|
||||
ports:
|
||||
- '9200:9200'
|
||||
- '9300:9300'
|
||||
volumes:
|
||||
- d:/docker-data/es:/usr/share/elasticsearch/data
|
||||
environment:
|
||||
- discovery.type=single-node
|
||||
- xpack.security.enabled=false
|
||||
labels:
|
||||
org.springframework.boot.service-connection: elasticsearch
|
||||
|
||||
kafka:
|
||||
image: bitnami/kafka:3.5
|
||||
container_name: kafka01
|
||||
restart: always
|
||||
ports:
|
||||
- "9092:9092"
|
||||
- "9094:9094"
|
||||
environment:
|
||||
- ALLOW_PLAINTEXT_LISTENER=yes
|
||||
- KAFKA_ENABLE_KRAFT=yes
|
||||
- KAFKA_CFG_LISTENERS=PLAINTEXT://:9092,CONTROLLER://:9093,EXTERNAL://:9094
|
||||
- KAFKA_CFG_ADVERTISED_LISTENERS=PLAINTEXT://kafka:9092,EXTERNAL://localhost:9094
|
||||
- KAFKA_CFG_LISTENER_SECURITY_PROTOCOL_MAP=CONTROLLER:PLAINTEXT,EXTERNAL:PLAINTEXT,PLAINTEXT:PLAINTEXT
|
||||
- KAFKA_CFG_INTER_BROKER_LISTENER_NAME=PLAINTEXT
|
||||
volumes:
|
||||
- d:/docker-data/kafka:/bitnami/kafka
|
||||
|
||||
|
|
@ -0,0 +1,67 @@
|
|||
<?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 https://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<parent>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-parent</artifactId>
|
||||
<version>3.1.1</version>
|
||||
<relativePath/> <!-- lookup parent from repository -->
|
||||
</parent>
|
||||
<groupId>net.risesoft</groupId>
|
||||
<artifactId>demo01</artifactId>
|
||||
<version>1.0</version>
|
||||
<name>demo01</name>
|
||||
<description>Demo project for Spring Boot</description>
|
||||
<properties>
|
||||
<java.version>17</java.version>
|
||||
</properties>
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-data-jpa</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-web</artifactId>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>com.mysql</groupId>
|
||||
<artifactId>mysql-connector-j</artifactId>
|
||||
<scope>runtime</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.projectlombok</groupId>
|
||||
<artifactId>lombok</artifactId>
|
||||
<optional>true</optional>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-docker-compose</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>
|
||||
<configuration>
|
||||
<excludes>
|
||||
<exclude>
|
||||
<groupId>org.projectlombok</groupId>
|
||||
<artifactId>lombok</artifactId>
|
||||
</exclude>
|
||||
</excludes>
|
||||
</configuration>
|
||||
</plugin>
|
||||
</plugins>
|
||||
</build>
|
||||
|
||||
</project>
|
|
@ -0,0 +1,13 @@
|
|||
package net.risesoft.demo;
|
||||
|
||||
import org.springframework.boot.SpringApplication;
|
||||
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
||||
|
||||
@SpringBootApplication
|
||||
public class Demo01Application {
|
||||
//
|
||||
public static void main(String[] args) {
|
||||
SpringApplication.run(Demo01Application.class, args);
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,29 @@
|
|||
package net.risesoft.demo;
|
||||
|
||||
import org.springframework.boot.autoconfigure.service.connection.ConnectionDetails;
|
||||
import org.springframework.boot.context.event.ApplicationReadyEvent;
|
||||
import org.springframework.context.ApplicationListener;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import net.risesoft.demo.entity.User;
|
||||
import net.risesoft.demo.repository.UserRepository;
|
||||
|
||||
@Component
|
||||
public class OnApplicationReady implements ApplicationListener<ApplicationReadyEvent> {
|
||||
|
||||
@Override
|
||||
public void onApplicationEvent(ApplicationReadyEvent event) {
|
||||
System.out.println(event.getApplicationContext().getEnvironment().getProperty("path"));
|
||||
String[] ss = event.getApplicationContext().getBeanNamesForType(ConnectionDetails.class);
|
||||
for (String s : ss) {
|
||||
System.out.println(s);
|
||||
}
|
||||
|
||||
UserRepository userRepository = event.getApplicationContext().getBean(UserRepository.class);
|
||||
User user = new User();
|
||||
user.setName("张三");
|
||||
user.setAge(20);
|
||||
userRepository.save(user);
|
||||
|
||||
}
|
||||
}
|
|
@ -0,0 +1,27 @@
|
|||
package net.risesoft.demo.controller;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
import net.risesoft.demo.entity.User;
|
||||
import net.risesoft.demo.repository.UserRepository;
|
||||
|
||||
@RestController
|
||||
@RequestMapping("/api/users")
|
||||
public class UserController {
|
||||
|
||||
private final UserRepository userRepository;
|
||||
|
||||
public UserController(UserRepository userRepository) {
|
||||
super();
|
||||
this.userRepository = userRepository;
|
||||
}
|
||||
|
||||
@GetMapping
|
||||
public List<User> findAll(){
|
||||
return userRepository.findAll();
|
||||
}
|
||||
}
|
|
@ -0,0 +1,20 @@
|
|||
package net.risesoft.demo.entity;
|
||||
|
||||
import jakarta.persistence.Entity;
|
||||
import jakarta.persistence.GeneratedValue;
|
||||
import jakarta.persistence.Id;
|
||||
import lombok.Data;
|
||||
import lombok.NoArgsConstructor;
|
||||
|
||||
@Entity
|
||||
@Data
|
||||
@NoArgsConstructor
|
||||
public class User {
|
||||
|
||||
@Id
|
||||
@GeneratedValue
|
||||
private Integer id;
|
||||
private String name;
|
||||
private Integer age;
|
||||
|
||||
}
|
|
@ -0,0 +1,11 @@
|
|||
package net.risesoft.demo.repository;
|
||||
|
||||
import org.springframework.data.jpa.repository.JpaRepository;
|
||||
import org.springframework.stereotype.Repository;
|
||||
|
||||
import net.risesoft.demo.entity.User;
|
||||
|
||||
@Repository
|
||||
public interface UserRepository extends JpaRepository<User,Integer>{
|
||||
|
||||
}
|
|
@ -0,0 +1,40 @@
|
|||
package org.springframework.boot.docker.compose.service.connection.kafka;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import org.springframework.boot.autoconfigure.kafka.KafkaConnectionDetails;
|
||||
import org.springframework.boot.docker.compose.core.RunningService;
|
||||
import org.springframework.boot.docker.compose.service.connection.DockerComposeConnectionDetailsFactory;
|
||||
import org.springframework.boot.docker.compose.service.connection.DockerComposeConnectionSource;
|
||||
|
||||
class KafkaDockerComposeConnectionDetailsFactory extends DockerComposeConnectionDetailsFactory<KafkaConnectionDetails> {
|
||||
|
||||
KafkaDockerComposeConnectionDetailsFactory() {
|
||||
super("bitnami/kafka");
|
||||
}
|
||||
|
||||
@Override
|
||||
protected KafkaConnectionDetails getDockerComposeConnectionDetails(DockerComposeConnectionSource source) {
|
||||
return new KafkaDockerComposeConnectionDetails(source.getRunningService());
|
||||
}
|
||||
|
||||
static class KafkaDockerComposeConnectionDetails extends DockerComposeConnectionDetails
|
||||
implements KafkaConnectionDetails {
|
||||
|
||||
private final List<String> bootstrapServers;
|
||||
|
||||
KafkaDockerComposeConnectionDetails(RunningService service) {
|
||||
super(service);
|
||||
this.bootstrapServers = List.of("localhost:9094");
|
||||
// this.bootstrapServers =
|
||||
// List.of(service.env().get("bootstrapServers").split(","));
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<String> getBootstrapServers() {
|
||||
return this.bootstrapServers;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,4 @@
|
|||
# Connection Details Factories
|
||||
org.springframework.boot.autoconfigure.service.connection.ConnectionDetailsFactory=\
|
||||
org.springframework.boot.docker.compose.service.connection.kafka.KafkaDockerComposeConnectionDetailsFactory
|
||||
|
|
@ -0,0 +1 @@
|
|||
spring.jpa.generate-ddl=true
|
Loading…
Reference in New Issue