Convert Figma logo to code with AI

ityouknow logospring-boot-examples

about learning Spring Boot via examples. Spring Boot 教程、技术栈示例代码,快速简单上手教程。

30,165
12,351
30,165
11

Top Related Projects

Spring Boot

36,477

Just Announced - "Learn Spring Security OAuth":

spring boot 实践学习案例,是 spring boot 初学者及核心技术巩固的最佳实践。

《Spring Boot基础教程》,2.x版本持续连载中!点击下方链接直达教程目录!

🚀一个用来深入学习并实战 Spring Boot 的项目。

77,204

mall项目是一套电商系统,包括前台商城系统及后台管理系统,基于SpringBoot+MyBatis实现,采用Docker容器化部署。 前台商城系统包含首页门户、商品推荐、商品搜索、商品展示、购物车、订单流程、会员中心、客户服务、帮助中心等模块。 后台管理系统包含商品管理、订单管理、会员管理、促销管理、运营管理、内容管理、统计报表、财务管理、权限管理、设置等模块。

Quick Overview

The ityouknow/spring-boot-examples repository is a collection of sample projects built using the Spring Boot framework. It provides a comprehensive set of examples that demonstrate the various features and capabilities of Spring Boot, making it a valuable resource for developers who are learning or working with the framework.

Pros

  • Comprehensive Examples: The repository covers a wide range of Spring Boot use cases, from basic web applications to more advanced topics like security, messaging, and microservices.
  • Well-Documented: Each example includes a detailed README file that explains the purpose, setup, and key features of the project.
  • Active Maintenance: The repository is actively maintained, with regular updates and bug fixes.
  • Community Engagement: The project has a strong community of contributors and users, providing a platform for collaboration and knowledge sharing.

Cons

  • Potential Outdated Versions: Some of the examples may use older versions of Spring Boot or related technologies, which could require additional effort to update to the latest versions.
  • Lack of Detailed Explanations: While the README files provide a good overview, they may not always go into deep technical details for each example.
  • Scattered Organization: The repository contains a large number of examples, which can make it challenging to navigate and find specific use cases.
  • Limited Deployment Guidance: The examples focus on the code itself, but may not provide comprehensive guidance on deployment and production-ready configurations.

Code Examples

Example 1: Basic Web Application

@SpringBootApplication
public class BasicWebApplication {

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

    @RestController
    public class HelloController {

        @GetMapping("/")
        public String hello() {
            return "Hello, Spring Boot!";
        }
    }
}

This example demonstrates a basic Spring Boot web application that exposes a simple GET endpoint at the root URL, returning the message "Hello, Spring Boot!".

Example 2: Security Configuration

@Configuration
@EnableWebSecurity
public class SecurityConfiguration extends WebSecurityConfigurerAdapter {

    @Override
    protected void configure(HttpSecurity http) throws Exception {
        http.authorizeRequests()
            .antMatchers("/admin/**").hasRole("ADMIN")
            .antMatchers("/user/**").hasRole("USER")
            .anyRequest().authenticated()
            .and()
            .formLogin()
            .and()
            .logout();
    }

    @Override
    protected void configure(AuthenticationManagerBuilder auth) throws Exception {
        auth.inMemoryAuthentication()
            .withUser("admin").password("{noop}password").roles("ADMIN")
            .and()
            .withUser("user").password("{noop}password").roles("USER");
    }
}

This example demonstrates a basic security configuration for a Spring Boot application, where the /admin/** endpoints are accessible only to users with the "ADMIN" role, and the /user/** endpoints are accessible only to users with the "USER" role.

Example 3: Messaging with RabbitMQ

@SpringBootApplication
public class RabbitMQApplication {

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

    @Component
    public class MessageSender {

        @Autowired
        private RabbitTemplate rabbitTemplate;

        public void sendMessage(String message) {
            rabbitTemplate.convertAndSend("my-exchange", "my-routing-key", message);
        }
    }

    @Component
    public class MessageReceiver {

        @RabbitListener(queues = "my-queue")
        public void receiveMessage(String message) {
            System.out.println("Received message: " + message);
        }
    }
}

This example demonstrates how to use RabbitMQ for messaging in a Spring Boot application. The MessageSender class sends a message to the RabbitMQ exchange, and the MessageReceiver class listens for messages on a specific queue and logs the received message.

Getting Started

To get started with the `ityouknow/spring-boot-

Competitor Comparisons

Spring Boot

Pros of spring-boot

  • Official Spring Boot repository, providing the core framework and documentation
  • Extensive test coverage and continuous integration
  • Regular updates and releases with detailed changelogs

Cons of spring-boot

  • Steeper learning curve for beginners due to its comprehensive nature
  • Less focus on practical examples and real-world use cases
  • May be overwhelming for developers seeking quick, specific implementations

Code Comparison

spring-boot (Configuration class):

@Configuration
@EnableAutoConfiguration
@ComponentScan
public class Application {
    public static void main(String[] args) {
        SpringApplication.run(Application.class, args);
    }
}

spring-boot-examples (HelloWorld controller):

@RestController
public class HelloWorldController {
    @RequestMapping("/hello")
    public String index() {
        return "Hello World";
    }
}

The spring-boot repository focuses on core framework code, while spring-boot-examples provides practical implementations and tutorials for various Spring Boot features. spring-boot is ideal for understanding the framework's internals and contributing to its development, whereas spring-boot-examples is better suited for learning and quick reference when building Spring Boot applications.

36,477

Just Announced - "Learn Spring Security OAuth":

Pros of tutorials

  • Broader scope, covering various Java frameworks and technologies beyond Spring Boot
  • More comprehensive, with a larger number of examples and tutorials
  • Regular updates and active community engagement

Cons of tutorials

  • Can be overwhelming due to the vast amount of content
  • May lack the focused, in-depth Spring Boot coverage found in spring-boot-examples

Code Comparison

spring-boot-examples:

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

tutorials:

@Configuration
@EnableAutoConfiguration
@ComponentScan
public class Application {
    public static void main(String[] args) {
        SpringApplication.run(Application.class, args);
    }
}

Summary

Both repositories offer valuable resources for Java developers. spring-boot-examples provides a focused approach to Spring Boot, making it ideal for those specifically interested in this framework. tutorials, on the other hand, offers a wider range of topics and examples, catering to developers looking to explore various Java technologies.

The code comparison shows that both repositories use similar basic Spring Boot application structures, with tutorials demonstrating a more explicit configuration approach. Ultimately, the choice between these repositories depends on the developer's specific learning goals and preferences.

spring boot 实践学习案例,是 spring boot 初学者及核心技术巩固的最佳实践。

Pros of springboot-learning-example

  • More comprehensive coverage of Spring Boot features, including advanced topics like Spring Cloud and microservices
  • Better organized structure with clear categorization of examples
  • More frequent updates and active maintenance

Cons of springboot-learning-example

  • Less beginner-friendly, with fewer explanations and comments in the code
  • Smaller community engagement, with fewer stars and forks on GitHub
  • Some examples may be outdated or not aligned with the latest Spring Boot best practices

Code Comparison

spring-boot-examples:

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

springboot-learning-example:

@SpringBootApplication
@EnableScheduling
public class Application {
    public static void main(String[] args) {
        SpringApplication.run(Application.class, args);
    }
}

The main difference in the code snippets is that springboot-learning-example includes the @EnableScheduling annotation, demonstrating more advanced configuration options in its examples.

《Spring Boot基础教程》,2.x版本持续连载中!点击下方链接直达教程目录!

Pros of SpringBoot-Learning

  • More comprehensive coverage of Spring Boot topics
  • Better organization with separate branches for different Spring Boot versions
  • Includes more advanced topics like microservices and cloud deployment

Cons of SpringBoot-Learning

  • Less frequent updates compared to spring-boot-examples
  • Fewer contributors, potentially limiting diverse perspectives
  • Some examples may be outdated for the latest Spring Boot versions

Code Comparison

SpringBoot-Learning:

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

spring-boot-examples:

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

The SpringBoot-Learning example includes @EnableDiscoveryClient, demonstrating integration with service discovery, while spring-boot-examples keeps it simpler with just the basic @SpringBootApplication annotation.

Both repositories offer valuable resources for learning Spring Boot, with SpringBoot-Learning providing more depth and spring-boot-examples offering a broader range of simpler examples. The choice between them depends on the learner's experience level and specific learning goals.

🚀一个用来深入学习并实战 Spring Boot 的项目。

Pros of spring-boot-demo

  • More comprehensive coverage of Spring Boot features and integrations
  • Better organized project structure with clear module separation
  • More frequent updates and active maintenance

Cons of spring-boot-demo

  • Potentially overwhelming for beginners due to its extensive scope
  • Less focused on basic Spring Boot concepts compared to spring-boot-examples

Code Comparison

spring-boot-demo:

@SpringBootApplication
@EnableScheduling
@EnableAsync
public class SpringBootDemoTaskApplication {
    public static void main(String[] args) {
        SpringApplication.run(SpringBootDemoTaskApplication.class, args);
    }
}

spring-boot-examples:

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

The spring-boot-demo example includes additional annotations for enabling scheduling and asynchronous execution, demonstrating a more feature-rich approach. In contrast, the spring-boot-examples code showcases a simpler, more straightforward implementation focusing on core Spring Boot functionality.

Both repositories serve as valuable resources for learning Spring Boot, with spring-boot-demo offering a wider range of advanced topics and integrations, while spring-boot-examples provides a more accessible entry point for newcomers to the framework.

77,204

mall项目是一套电商系统,包括前台商城系统及后台管理系统,基于SpringBoot+MyBatis实现,采用Docker容器化部署。 前台商城系统包含首页门户、商品推荐、商品搜索、商品展示、购物车、订单流程、会员中心、客户服务、帮助中心等模块。 后台管理系统包含商品管理、订单管理、会员管理、促销管理、运营管理、内容管理、统计报表、财务管理、权限管理、设置等模块。

Pros of mall

  • Comprehensive e-commerce solution with a wide range of features
  • Well-structured and modular architecture for scalability
  • Detailed documentation and deployment guides

Cons of mall

  • Steeper learning curve due to its complexity
  • May be overkill for simpler projects or learning purposes
  • Requires more resources to run and maintain

Code comparison

mall:

@Configuration
@EnableWebSecurity
public class SecurityConfig extends WebSecurityConfigurerAdapter {
    @Override
    protected void configure(HttpSecurity httpSecurity) throws Exception {
        httpSecurity.csrf()
                    .disable()
                    .sessionManagement()
                    .sessionCreationPolicy(SessionCreationPolicy.STATELESS)
                    .and()
                    .authorizeRequests()
                    .antMatchers("/admin/**").hasRole("ADMIN")
                    .anyRequest().authenticated();
    }
}

spring-boot-examples:

@Configuration
@EnableWebSecurity
public class WebSecurityConfig extends WebSecurityConfigurerAdapter {
    @Override
    protected void configure(HttpSecurity http) throws Exception {
        http.authorizeRequests()
            .antMatchers("/", "/home").permitAll()
            .anyRequest().authenticated()
            .and()
            .formLogin()
            .loginPage("/login")
            .permitAll();
    }
}

The mall project provides a more comprehensive security configuration, including CSRF protection and session management, while spring-boot-examples offers a simpler setup focused on basic authentication and authorization.

Convert Figma logo designs to code with AI

Visual Copilot

Introducing Visual Copilot: A new AI model to turn Figma designs to high quality code using your components.

Try Visual Copilot

README

Spring Boot 学习示例

Spring Boot 2.0 Mysql 5.6 JDK 1.8 Maven license

Spring Boot 使用的各种示例,以最简单、最实用为标准,此开源项目中的每个示例都以最小依赖,最简单为标准,帮助初学者快速掌握 Spring Boot 各组件的使用。

Spring Boot 中文索引  |   Spring Cloud学习示例代码  |   Spring Boot 精品课程

Github地址  |   码云地址  |   Spring Boot 1.X |   Spring Boot 2.X


本项目中所有示例均已经更新到 Spring Boot 3.0

  • Spring Boot 1.X 系列示例代码请看这里:Spring Boot 1.X
  • Spring Boot 2.X 系列示例代码请看这里:Spring Boot 2.X

示例代码

如果大家想了解关于 Spring Boot 的其它方面应用,也可以以issues的形式反馈给我,我后续来完善。

关注公众号:纯洁的微笑,回复"666"进群交流