Java를 공부하다 보면 new 키워드로 객체를 생성하고, 해당 객체의 메서드를 호출해 기능을 구현하게 된다. 이렇게 Java만으로도 충분히 프로그램을 만들 수 있는데, 왜 많은 Java 백엔드 애플리케이션에서는 Spring Framework를 사용하는 걸까? Spring이 없어도 객체를 생성할 수 있고, 비즈니스 로직을 구현할 수 있으며, 데이터베이스에 접근하는 코드도 작성할 수 있다. ❓ 그렇다면 Spring은 무엇을 해결해 주는 걸까? 이 질문에 답하기 위해 Spring 없이 작성한 Java 코드에서 출발해, Spring Framework가 등장한 배경과 제공하는 기능들을 살펴보려고 한다. 1. 순수 Java로 애플리케이션을 개발한다면? 먼저 Spring을 사용하지 않고 간단한 주문 처리 프로그램을 만든다고 가정해 보자. 주문을 처리하는 OrderService와 주문 정보를 저장하는 OrderRepository가 필요하다.
Is this you? As a journalist, you can create a free Muck Rack account to customize your profile, list your contact preferences, and upload a portfolio of your best work.
Claim your profile
Articles by import org.springframework.context.annotation.Bean
Kafka 전용 코드 리뷰: 커피주문 event가 수집 되기까지
1. 메시지의 길 POST /api/orders → OrderService → MySQL 주문 + outbox (같은 DB 트랜잭션) OutboxScheduler → OutboxPublisher → KafkaOrderEventSender → orders.paid 토픽 orders.paid 토픽 → AnalyticsConsumer → AnalyticsService → MySQL 수집 기록 토픽은 Kafka의 메시지 이름표가 붙은 저장 공간이다. 파티션은 한 토픽을 나눈 줄이다. 프로듀서는 메시지를 보내고 컨슈머는 읽는다. 이 코드에서는 OrderEvent 한 개가 주문 완료 사건 한 개를 나타낸다. 2. 주문과 Kafka를 한 번에 직접 처리하지 않는 이유 MySQL과 Kafka는 서로 다른 시스템이다. 주문을 DB에 저장한 직후 서버가 꺼지면 Kafka 전송이 빠질 수 있다. 그래서 OrderService가 주문과 outbox 행을 같은 MySQL 트랜잭션에 저장한다.
비밀번호 암호화(1)
build.gradle dependencies { implementation 'org.springframework.security:spring-security-crypto' } build.gradle에 이걸 넣어준다 Spring Security Crypto 모듈은 Spring Security의 일부이지만, 전체 Spring Security를 사용하지 않고 암호화 기능만 사용할 수 있습니다. BCryptPasswordEncoder를 사용하기 위한 최소한의 의존성입니다.
[TIL] _ 260214 _ 스프링 빈을 배우다 🫛
스프링 빈과 의존관계 회원 컨트롤러가 회원 서비스와 리포지토리를 사용할 수 있게 의존관계로 설정 보통 라이브러리는 코드를 만드는 사람이 호출해서 사용하지만, 스프링은 반대로 스프링이 주도권을 잡아서 내 코드에 붙은 애노테이션을 보고 라이브러리를 호출해서 실행한다. 그리고 우리는 어떤 라이브러리를 스프링이 가져다 쓰는지 몰라도 된다. ➡️ 제어의 역전 (IoC)과 추상화 스프링은 실행되면 먼저 스프링 컨테이너 라는 공간을 만든다. 컴포넌트 스캔과 자동 의존관계 설정 컴포넌트 (Component) 소프트웨어 공학에서 컴포넌트(Component)는 "교체가 가능한 독립된 부품"이라는 뜻이다. 스프링은 클래스를 단순한 코드가 아니라, 언제든 갈아 끼울 수 있는 '부품'으로 취급한다. 그래서 그 클래스 위에 시스템의 부품(Component) 도장을 찍어두는 역할을 하는 애노테이션의 한 종류다.
Spring Bean을 수동으로 등록해보자
Spring에서는 Bean을 등록하는 두 가지 방식이 존재합니다. 1. 자동 등록 (Component Scan) @Component @Controller @Service @Repository public class MyService { } 2.
Spring에서 RabbitMQ 사용법
Spring 서버가 Producer 역할을 하도록 하는 방법을 설명한다. 그 중 direct exchange를 구현한다. RabbitMQ에 대한 설명은 아래 글에 적어두었다. RabbitMQ 개념 알아보기 RabbitMQ 서버는 로컬에 container로 띄울 것이다.
섹션 1. 스프링 시큐리티 기본
Repository: https://github.com/goodispotato/spring_boot_security root 로그인 후 입력 application.properties > spring.application.name=security1 server.port=8080 server.servlet.context-path=/ server.servlet.encoding.charset=UTF-8 server.servlet.encoding.enabled=true server.servlet.encoding.force=true spring.datasource.driver-class-name=com.mysql.cj.jdbc.Driver spring.datasource.url=jdbc:mysql://localhost:3306/security?serverTimezone=Asia/Seoul spring.datasource.username=cos...
회원 도메인 & 초기 데이터
프로젝트를 시작할 때 개발/테스트 효율을 위해 샘플 데이터를 자동으로 생성해두면 편하다. 이 글에서는 다음 흐름으로 초기 데이터를 구성한다. ApplicationRunner로 초기 데이터 실행 구조 만들기 @Slf4j 로깅으로 출력 제어 MemberService/MemberRepository 기반으로 회원 샘플 생성 샘플 생성 로직을 트랜잭션 하나로 묶기 중복 username 처리: DB 제약 → 앱 레벨 체크 → 커스텀 예외 JPA Auditing으로 생성일/수정일 자동화 BaseEntity로 공통 필드 추상화 1) ApplicationRunner로 초기 데이터 실행 구조 만들기 스프링에서 ApplicationRunner 빈을 등록하면 애플리케이션 시작 시 자동 실행된다. 또한 run()은 모든 빈 초기화 이후 호출되므로, 샘플 데이터 생성 같은 작업에 적합하다.
Java Spring Framework 시작하기
Spring이 필요한 이유? Spring을 통해 다양한 애플리케이션(웹, REST API, Full Stack, Microservice) 빌드 가능. 쉽게 문제 디버깅할 수 있음. Spring Boot에 대한 빠른 이해를 도움. 개발 생산성을 높이기 위해 사용! Spring Framework: App 구축에 필요한 기능 제공 (“의존성 주입”과 “자동 연결”) Spring Boot: Spring Framework를 쉽게 사용하기 위한 방법. Coupling 무언가를 변경하는데 얼마나 많은 작업이 관련되어 있는지에 대한 측정 Tight Coupling (iteration 1) 자동차-엔진: tight coupling 자동자-바퀴: loose coupling 코드는 지속적으로 변화하기 때문에, loose coupling을 사용하는 것이 바람직함. 가능한 한 코드 변경을 최소화하면서 기능을 변경할 수 있어야 함.
【解决问题】---- 关于Long类型数据前端丢失精度问题解决办法
原创 已于 2025-08-29 10:23:57 修改 · 276 阅读 · 6 · 2 · CC 4.0 BY-SA版权 版权声明:本文为博主原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。 于 2025-08-29 10:03:21 首次发布 前言: 问题:关于Long类型数据前端丢失精度问题解决办法,后端由于字符内容过长,前端展示精度丢失修复 虽然我们在 Swagger 接口测试中并没有看到精度丢失的错误,但是在测试中,如果你打开 F12 控制台,利用预览来查 看响应数据,就会发现另一个问题:id 的最后 两位好像都变成 0 了! 这是由于前端 JS 的精度范围有限,我们后端返回的 ID 范围过大,导致前端精度丢失,会影响前端页面获取到的数据结果。 为了解决这个问题,可以在后端 config 包下新建一个全局 JSON 的配置,将整个后端 Spring MVC 接口返回的值的长整型数字转换为字符串进行返回,从而集中解决问题。 package com.rainbowsea.yupicturebackend.config;...
尚庭公寓----------分页查询-CSDN博客
根据条件分页查询公寓列表 进行分页配置 package com.nie.lease.common.mybatisplus; import com.baomidou.mybatisplus.annotation.DbType; import com.baomidou.mybatisplus.extension.plugins.MybatisPlusInterceptor; import com.baomidou.mybatisplus.extension.plugins.inner.PaginationInnerInterceptor; import org.mybatis.spring.annotation.MapperScan; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; @Configuration @MapperScan("com.nie.lease.web.*.mapper")...
基于 SpringBoot 实现一个 JAVA 代理 HTTP / WS
猪悟道 于 2025-06-29 15:10:21 发布 阅读量1k 收藏 30 点赞数 18 分类专栏: Netty 学习 JavaWeb 服务框架 文章标签: spring boot http web socket spring proxy 代理 jdk21 版权声明:本文为博主原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。 1.环境信息 组件版本 JDK 21 Springboot 3.5.3 netty-all 4.1.108.Final smiley-http-proxy-servlet 2.0 2.项目结构和代码 2.1 项目结构 2.2 依赖包 <?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"...
Vue + Spring Boot 整合全解析
在当今的Web开发领域,前后端分离架构已成为主流。Vue.js作为一款流行的前端框架,以其简洁易用和高效的特点深受开发者喜爱;Spring Boot则是Java后端开发中快速构建应用的利器。将Vue和Spring Boot整合,能够充分发挥两者的优势,打造出高性能、易维护的Web应用。本文将详细介绍如何进行Vue + Spring Boot的整合。 前端环境:确保已安装Node.js,它是运行Vue项目所必需的。可从Node.js官网下载并安装。安装完成后,通过node -v和npm -v命令检查版本,确保安装成功。 后端环境:安装JDK(建议JDK 8及以上)和Maven。可从Oracle官网下载JDK,从Maven官网下载Maven。配置好相应的环境变量后,通过java -version和mvn -v命令验证安装。 使用Spring Initializr快速创建项目: 访问Spring Initializr,在网页上进行项目初始化配置。选择Maven项目,语言为Java,Spring...
How to Use Spring's @Profile Annotation for Flexible Configurations
The @Profile annotation in Spring allows you to segregate configurations to be available only in specific environments. If you mark a @Component (and its specializations) or any @Configuration or @Bean with the @Profile annotation, it will make them available only if the profile specified is active. You can set the profile using application.properties by using the spring.profiles.active property, or by specifying it in the command line when running the application.
springboot框架集成websocket依赖实现物联网设备、前端网页实时通信!_springboot 实现websocket,前端接收消息-CSDN博客
需求: 最近在对接一个物联网里设备,他的通信方式是 websocket 。所以我需要在 springboot框架中集成websocket 依赖,从而实现与设备实时通信! 框架:springboot2.7 java版本:java8 好了,还是直接上代码 第一步:引入依赖 <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-websocket</artifactId> </dependency> 第二步写配置: package com.agentai.base.config; import com.agentai.base.yumou.webSocket.YuMouDeviceWebSocketHandler; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; import...
【微服务架构】SpringSecurity核心源码剖析+jwt+OAuth(十二):SpringSecurity中OAuth2.0的实现(OAuth2.0实战案例【下】)-CSDN博客
个人主页:道友老李 欢迎加入社区:道友老李的学习社区 Spring Security Spring Security 是一个功能强大且高度可配置的安全框架,用于为 Java 应用程序提供身份验证和授权功能。以下是对它的详细介绍: 身份验证:支持多种身份验证方式,如用户名 / 密码、OAuth、LDAP 等。可以方便地与各种身份验证源集成,如数据库、LDAP 目录、OAuth 提供商等。例如,在一个 Web 应用中,用户可以通过输入用户名和密码进行登录,Spring Security 会验证用户提供的凭据是否有效。 授权:提供了细粒度的授权控制,可以基于角色、权限或自定义的访问规则来限制对资源的访问。比如,只有具有特定角色(如管理员)的用户才能访问某些敏感的 API 端点或页面。 防止常见攻击:自动防范常见的安全漏洞,如跨站请求伪造(CSRF)、会话固定攻击、点击劫持等。 过滤器链:Spring Security 基于 Servlet...
Redis入门:Redis中的数据结构和在Java中的实现_redis 的zset操作 java实现-CSDN博客
目录 Redis数据结构概览 由于Redis是一个key-value的数据库,key一般是String类型,不过value的类型多种多样: 其数据结构又可以分为基本类型和特殊类型 基本类型: 1.字符串(String)—— 最简单的数据容器 2.列表(List)—— 双向链表结构 3.集合(Set)—— 无序唯一元素集合 4.有序集合(Sorted Set)—— 带分数的集合 5.哈希表(Hash)—— 键值对的集合 特殊类型: 1.GEO类型——主要用于存储地理坐标(例如经纬度等,例:{北京(39.906217, 116.3912757)}),用于实现位置查询等; 2.BitMap类型——用于用户签到、状态标记等场景。 3.HyperLogLogs:近似统计唯一用户数,节省内存。 其他类型可参考Redis官方文档:Docs (redis.io) 核心数据结构深度解析 前文已经介绍过了Redis是key-value结构,所以,对于这个key,其实也允许有多个单词形成层级结构,多个单词之间使用“:”隔开:格式如下: 项目名:业务名:类型:id 这样做可以很好的解决key冲突的问题...
asdfg
package com.infra_automation.config; import java.util.List; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Value; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; import org.springframework.security.authentication.AuthenticationManager; import org.springframework.security.config.Customizer; import...
Spring 核心技术解析【纯干货版】- XX:Spring 测试模块 Spring-Test 模块精讲
在现代软件开发中,测试是确保代码质量和稳定性的重要环节。Spring 提供了 Spring-Test 模块,专门用于支持单元测试和集成测试,帮助开发者轻松模拟 Spring 容器环境,测试各种 Spring 组件,如 Bean、事务、数据库交互、Web 控制器等。 本篇文章将详细解析 Spring-Test 模块的核心功能,并通过 JUnit 5 案例,展示如何在 非 Spring Boot 项目 中编写高效的 Spring 测试代码,助力提升代码的稳定性和可维护性。 1、Spring-Test 模块介绍 1.1、Spring-Test 模块概述 Spring-Test 是 Spring 框架中的测试模块,提供了一系列工具和支持,帮助开发者编写单元测试和集成测试,确保 Spring 应用的稳定性和可靠性。它支持 JUnit 和 TestNG 框架,并提供了 Spring 容器上下文管理、事务管理和 Mock 测试等功能。 2.2、Spring-Test 模块依赖 Spring-Test 主要依赖以下模块: Spring-Core:提供基础核心功能。...
AWS SNS with Spring Boot and Email as subscriber
Introduction The concepts of "topic" and "subscribe" are often linked, especially in contexts like messaging systems, event-driven architectures, or content platforms. Publisher: This is the source or entity that produces messages or events. The publisher doesn't need to know who will consume its messages. Topic: This acts as a channel or intermediary that categorizes messages. Publishers post messages to specific topics, and subscribers listen to those topics.
【消息利器RabbitMQ】RabbitMQ常用内容浅析 - 佛祖让我来巡山 - 博客园
以下是一篇关于 RabbitMQ 的博客内容,涵盖了从基础到死信队列的实现,以及 RabbitMQ 其他常用知识点的补充。内容逻辑清晰,代码完整,适合直接发布。 在现代分布式系统中,消息队列(如 RabbitMQ)是解耦和异步通信的重要工具。本文将基于 Spring Boot 和 RabbitMQ,从基础到高级,逐步实现以下功能: 发送消息到队列。 发送消息到交换机。 消息可靠性机制: 消息确认机制(Publisher Confirms)。 消息持久化(Durable Queues and Messages)。 消费者手动确认(Manual Acknowledgement)。 死信队列(Dead Letter Queue, DLQ):处理无法被正常消费的消息。 我们将使用一个简单的 User 对象作为消息内容,User 类包含 name 和 age 字段。 1.
OAuth 1.0 Authentication in Spring Boot
OAuth 1.0 is a protocol that allows secure authorization in a decentralized manner using cryptographic signatures. Unlike OAuth 2.0, OAuth 1.0 does not use bearer tokens but rather digitally signed requests. 1. Understanding OAuth 1.0 OAuth 1.0 provides: Secure API access using signatures (HMAC-SHA1, RSA-SHA1, or PLAINTEXT) Request Token & Access Token exchange User authorization via a redirect-based flow Stateless communication between clients and servers 2.
@Bean annotation example in spring boot
Directory Structure 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 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.4.3</version> <relativePath/> <!-- lookup parent from repository -->...
【第1到23讲】 基于vue + spring boot学生宿舍管理系统(文末附项目完整源代码+万字文档)
基于vue + spring boot学生宿舍管理 1、环境准备 1、安装node.js 2、安装vue-cli 3、安装 vs code开发工具 2、下载node.js 浏览器打开 https://nodejs.org/zh-cn/download/ 进入下载 1.2点击【以往的版本】进入所示列表界面,选择自己所需要的版本进行下载安装 3、vue-cli安装 1.2.1检查node.js是否安装 通过命令提示符,node -v npm -v查看,如果没有请先安装node.js,如下图,说明已经安装node.js 1.2.2.把npm换成cnpm 命令工具输入 npm install -g cnpm --registry=https://registry.npm.taobao.org 安装完成 输入 cnpm -v 查看是否安装成功 卸载cnpm npm uninstall cnpm -g 1.2.3.安装vue-cli cnpm install -g @vue/cli 1.2.4.查看vue-cli是否安装成功 vue -V 注意 V是大写的 4、vs code安装...
SpringBoot集成Swagger指南-CSDN博客
在Spring Boot项目中集成Swagger可以帮助你自动生成API文档,并且提供一个交互式的UI界面,方便开发者测试和调试API。以下是集成Swagger的步骤: 1.
Swagger is a powerful tool for documenting and testing RESTful APIs. With Spring Boot 3, we can easily integrate Swagger using the OpenAPI specification. This tutorial will guide you through setting up Swagger in a Spring Boot 3 application and documenting a user management API. Setting Up Swagger in Spring Boot 3 Spring Boot 3 supports OpenAPI through the springdoc-openapi-starter-webmvc-ui dependency.
SpringBoot实战(三十四)集成 spring-security-oauth2(OAuth2的4个角色、5种认证方式、demo集成)
|
By import org.springframework.context.annotation.Bean, import org.springframework.context.annotation.Configuration, Import Org.springframework.security.config.annotation.authentication.builders.authentication ManagerBuilder, Import Org.springframework.security.config.annotation.web.builders. HttpSecurity
|
CSDN
1.1 什么是 OAuth2 协议? OAuth2(Open Authorization 2.0) 协议是 RFC 6749 文件,是一种 用于授权的开放标准协议,用于通过第三方应用程序访问用户在某个服务提供商上存储的资源,而无需共享用户的凭证(例如用户名和密码)。 OAuth 引入了一个授权层,用来分离两种不同的角色:客户端和资源所有者。…资源所有者同意以后,资源服务器可以向客户端颁发令牌。客户端通过令牌,去请求数据。 OAuth2.0 的运行流程如下图所示: (A)用户打开客户端以后,客户端要求用户给予授权。 (B)用户同意给予客户端授权。 (C)客户端使用上一步获得的授权,向认证服务器申请令牌。 (D)认证服务器对客户端进行认证以后,确认无误,同意发放令牌。 (E)客户端使用令牌,向资源服务器申请获取资源。 (F)资源服务器确认令牌无误,同意向客户端开放资源。 简而言之:你要获取我(资源服务器)的资源的话,得先找他(授权服务器)授权。 1.2 OAuth2 的4个角色 OAuth2.0 认证过程中,涉及到的四个角色如下 :...
5.RabbitMQ交换机详解_rabbitmq交换机类型-CSDN博客
五、RabbitMQ交换机详解 1、交换机类型 Exchange(X) 可翻译成交换机/交换器/路由器 RabbitMQ交换器 (Exchange)类型 Fanout Exchange(扇形交换机) Direct Exchange(直连交换机) Topic Exchange(主题交换机) Headers Exchange(头部交换机) x-local-random Exchange 自定义交换机 5.1.1、Fanout Exchange (1)、交换机简介 扇形交换机会将消息投递到所有绑定的队列,不需要路由键,不需要进行路由键的匹配,相当于广播、群发; (2)、使用示例 rabbitmq-05-fanout 添加依赖 <dependencies> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-amqp</artifactId> </dependency> <dependency>...
Seamless Authentication System: Integrating Keycloak with Spring Boot, Thymeleaf, and React Using OAuth2 and JWT
Authentication is a critical aspect of modern web applications, and Keycloak provides a powerful, open-source identity and access management solution. In this article, we’ll explore integrating Keycloak with a Spring Boot backend—using Thymeleaf for server-side rendering—and a React frontend styled with Tailwind CSS 4 and DaisyUI 5 (beta).
Transformig a Fintech Investment Platform: From PHP to Java (Spring Boot)
Project Overview Legacy code can be a major challenge for fintech platforms, particularly when dealing with aging PHP systems that are difficult to maintain and scale. To address these issues, we refactored an investment platform from PHP to Java, leveraging Spring Boot and SOAP-based APIs for improved reliability, performance, and maintainability.
详解 Spring 配置数据源的两种方式
在 Spring 框架中配置数据源(DataSource)主要有两种方式: 通过 Setter 注入配置数据源 通过 jdbc.properties 配置文件方式 本博文将使用 Druid 作为数据源,其在 Spring 项目中常见且高效。 Druid 被广泛认为是性能最佳的连接池之一,尤其在高并发场景下表现优异。它支持快速的连接获取和释放,优化了资源管理 ✅ 1.1 Maven 依赖 <dependency> <groupId>com.alibaba</groupId> <artifactId>druid</artifactId> <version>1.2.24</version> </dependency> ✅ 1.2 XML 配置 修改 applicationContext.xml 文件 <?xml version="1.0" encoding="UTF-8"?> <beans xmlns="http://www.springframework.org/schema/beans"...
【SpringSecurity】springboot整合SpringSecurity实现登录校验与权限认证_springboot security-CSDN博客
fixAllenSun 于 2025-02-25 14:06:16 发布 阅读量1.2k 收藏 27 点赞数 21 文章标签: spring boot 后端 java 版权声明:本文为博主原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。 【一】SpringSecurity框架简介 关于安全方面的两个主要区域是“认证”和“授权”(或者说是访问控制),一般来说,Web应用的安全性包括用户认证(Authentication)和用户授权(Authorization)两个部分,这两点也是SpringSecurity重要核心功能。 (1)用户认证指的是:验证某个用户是否为系统中的合法主体,也就是说用户能否访问该系统。用户认证一般要求用户提供用户名和密码。系统通过校验用户名和密码来完成认证过程。通俗点说就是系统认为用户是否能登录。...
πspring-note-006: Bean Definition Inheritance
(Reference: ) π‘ Spring allows one bean to inherit properties from another bean. π‘ Useful for reusing common configurations across multiple beans. π‘ Implemented via XML (parent attribute) or Java-based configuration (@Bean inheritance). β In traditional XML configuration, you can define a parent bean with common properties and let child beans inherit them.
Spring Security is responsible for authenticate and authorize Spring applications, it provide multiple way of doing authentication but Basic is probably the simplest. With basic authentication, for every request made to the api, we send the user credentials in the headers, generally encoded with Base64 format. Creating the Spring Boot application We keep it simple with only spring web and spring security.
Multi-Tenancy in Java-Based Microservice-Platform
Martin Simon I am a 34-year-old Java developer specializing in microservice architecture and team leadership. Based in the Austrian Alps, I work remotely for #onpier. Work Team Lead Development at onpier Joined
解决 Tomcat 跨域问题 - Tomcat 配置静态文件和 Java Web 服务(Spring MVC Springboot)同时允许跨域
解决 Tomcat 跨域问题 - Tomcat 配置静态文件和 Java Web 服务(Spring MVC Springboot)同时允许跨域 Tomcat 配置允许跨域 Web 项目配置允许跨域 Tomcat 同时允许静态文件和 Web 服务跨域 偶尔遇到一个 Tomcat 部署项目跨域问题,因为已经处理过太多跨域了,觉得很简单 。 结果尝试多次均不能达到想要的结果,又经过 Nginx、Tomcat 以及项目配置才完全搞定。 另外,之前总结了篇 Web 项目跨域问题(Geoserver),也可以综合参考。 本文包含 Tomcat 配置允许跨域、Web 项目配置允许跨域以及同时允许跨域三部分。 Tomcat 配置允许跨域 使用 Tomcat 作为静态文件服务还是比较简单和常用的,而跨域问题也比较容易解决。 Tomcat 静态文件允许跨域,设置比较简单,百度一搜一堆,这里简单贴一下。 1.Tomcat web.xml 配置允许所有跨域 设置之后,所有静态文件以及服务均被允许跨域。 (1) 当未配置允许跨域时,报跨域错误 浏览器直接访问是正常的: (2)Tomcat...
RedisTemplate执行lua脚本及Lua 脚本语言详解
使用RedisTemplate执行lua脚本 在开发中,我们经常需要与Redis数据库进行交互,而Redis是一个基于内存的高性能键值存储数据库,它支持多种数据结构,并提供了丰富的命令接口。在某些情况下,我们可能需要执行一些复杂的逻辑操作,这时可以使用Lua脚本来实现这些逻辑,而Redis提供了执行Lua脚本的功能。在Spring应用程序中,我们可以使用RedisTemplate来执行Lua脚本。 Redis本身提供了许多命令,可以完成各种操作,但有时候我们需要执行一些比较复杂的逻辑操作,这时使用Lua脚本可以帮助我们在一次网络往返中完成多个命令操作,减少了网络开销,提高了执行效率。此外,Lua脚本在Redis服务器端执行,可以减少客户端与服务器之间的通信次数,提高了性能。 结合Redis和lua脚本语言的特性,如果在Redis里遇到如下需求,就可以引入lua脚本。 重复执行相同类型的命令,比如要缓存1到1000的数字到内存里。 在高并发场景下减少网络调用的开销,一次性执行多条命令。 Redis会将lua脚本作为一个整体来执行,天然具有原子性。...
Spring boot对接安全证书
Let’s Encrypt 证书 在 macOS 上可以直接使用 Homebrew 安装 Certbot,并按照以下步骤生成 Let’s Encrypt 证书并配置到 Spring Boot 项目中。 1. 安装 Certbot 在 macOS 上使用 Homebrew 安装 Certbot: brew install certbot 2. 使用 Certbot 生成 SSL 证书 生成证书前,请确保 macOS 的防火墙允许 Certbot 的临时服务器监听 80 端口(Certbot 使用此端口验证域名归属)。运行以下命令生成证书: sudo certbot certonly --standalone -d yourdomain.com Certbot 会自动生成证书并将其保存在 /etc/letsencrypt/live/yourdomain.com/ 中,其中包含以下文件: fullchain.pem: 证书文件 privkey.pem: 私钥文件 3.
Springboot应用开发:配置类整理_spring-boot 3.2 setkeepalive-CSDN博客
目录 1.1 setCorePoolSize 1.2 setMaxPoolSize 1.3 setQueueCapacity 1.4 setKeepAliveSeconds 1.5 setThreadNamePrefix 三、Redis 3.1 setKeySerializer Welcome to Code Block's blog 本篇文章主要介绍了 [SpringBoot应用开发:配置类整理] ❤博主广交技术好友,喜欢文章的可以关注一下❤ 编写目的 在使用SpringBoot进行应用开发中,通常需要编写很多的配置类,这些配置类在很大程度上提高了应用的开发速度.其中就包括线程池、数据库连接池、缓存的相关配置类。在这里我将经常用到的配置类进行整理和总结。 一、线程池 线程池用于优化异步任务的执行速度、并发处理能力.控制线程数量,避免资源过度消耗.通过设置线程前缀可以提高日志的可读性.
Spring Security6 & OAuth2 实现流程
最新推荐文章于 2024-12-17 20:03:10 发布 陈奕迅本讯 最新推荐文章于 2024-12-17 20:03:10 发布 阅读量1.4k 收藏 20 点赞数 18 文章标签: spring java 后端 版权声明:本文为博主原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。 一 通用的权限框架需求 1 响应数据格式需要统一 示例 { "code": "success", "message": "description", "data": null } ps: code: 状态码,后台定义给前端用,比如“token.expired”,前端收到这个状态码后,会立刻去调用刷新token接口 message: 状态码含义描述,可以做国际化翻译。不同语言返回不同的翻译版本(这个用不到,就不演示了) 重点:正常情况 和 异常情况 返回的数据格式都必须一样 实战 我们通过一个案例来模拟成功与失败的返回 定义Controller,实现两个api来模拟成功和失败。然后定义一个返回结果类Result 来规范统一的返回结果...
java.io.IOException: Broken pipe 异常分析
org.apache.catalina.connector.ClientAbortException: java.io .IOException: Broken pipe 是一个常见的Java异常,通常在使用Tomcat服务器处理HTTP请求时出现。这个异常表示客户端在服务器完成响应之前关闭了连接,导致服务器端试图写入数据到一个已经关闭的连接上。具体来说,“Broken pipe”(断开的管道)意味着客户端与服务器之间的连接在数据传输过程中被意外中断。 异常原因 服务器处理时间过长:如果服务器处理请求的时间超过了客户端设置的超时时间,客户端可能会中断连接。 解决方案: 优化服务器性能:减少API响应时间,优化代码逻辑,提高服务器处理效率。 调整超时时间 a.
Configurable Feign Client Retry With Reusable Library, DRY
In microservice architectures, resilient communication between services is vital. Feign, a declarative web service client, is a popular choice for simplifying HTTP communication. But there is no out-of-the-box retry mechanism provided, which can be plugged seamlessly with the Feign client. This is a good-to-have feature, as adding retry logic to Feign clients enhances fault tolerance.
Login system with JWT token and email reset password
Introduction The Spring Login Application is a secure and robust user management system built using Spring Boot. This project demonstrates modern approaches to implementing authentication, authorization, and user account functionalities. Key features include user registration, secure password handling with BCrypt, email-based password reset, and JWT (JSON Web Token) authentication.
High-Performance Reactive REST API, DB Connection
Reactive Programming Reactive programming is a programming paradigm that manages asynchronous data streams and automatically propagates changes, enabling systems to react to events in real time. It’s useful for creating responsive APIs and event-driven applications, often applied in UI updates, data streams, and real-time systems. WebFlux is designed for applications with high concurrency needs.
一文彻底搞定Spring Security 认证,实现登陆登出功能
Spring Security 是一个强大且灵活的安全框架,提供了身份验证(认证)和授权(授权)功能。下面我们将详细介绍 Spring Security 的认证功能流程,并提供自定义实现登录接口的示例,包括自定义认证过滤器和登出功能。 Spring Security 的认证流程是多层次的,涉及多个组件的协作。以下是每个步骤的深入分析: 请求拦截 当用户请求一个受保护的资源时,Spring Security 会使用过滤器链来处理请求。FilterChainProxy 是 Spring Security 的核心过滤器,它将请求传递给注册的过滤器链。 认证过滤器 默认情况下,UsernamePasswordAuthenticationFilter 会被用作处理用户名和密码的认证。它从请求中提取认证信息,通常是通过 POST 请求的表单数据传递。 关键方法 attemptAuthentication 中,使用 AuthenticationManager 来处理认证请求。AuthenticationManager 负责委托认证给具体的认证提供者。...
Spring Boot and RabbitMQ: Messaging with AMQP
Learn to integrate RabbitMQ with Spring Boot for scalable messaging with AMQP Messaging systems play a critical role in enabling communication between microservices in modern applications. One of the most widely used messaging brokers for Java applications is RabbitMQ, which uses the Advanced Message Queuing Protocol (AMQP) to facilitate this communication. When paired with Spring Boot, RabbitMQ simplifies the task of implementing reliable messaging within applications.
How to Implement Fine-Grained Authorization in Java and SpringBoot
Securing your application goes beyond simply granting or denying access at the surface level. As a developer, you need to implement fine-grained authorization (FGA) to manage permissions at a more detailed, granular level. FGA allows you to set up detailed access controls that specify who can do what and under which conditions. In this tutorial, you will learn how to implement fine-grained authorization in Java and Spring Boot using Permit.io. Here is the source code (remember to give it a star ⭐).
The Ultimate Guide to IOC Containers: Understanding Spring, Guice, and Dagger for Effective Dependency Injection
Introduction In modern software development, managing dependencies and ensuring the loose coupling of components are crucial for creating scalable and maintainable applications. An Inversion of Control (IOC) Container is a powerful design pattern that aids developers in achieving this goal. By delegating the instantiation and lifecycle management of objects, an IOC container enhances code readability, testability, and modularity.
Fullstack app: Developing the Back-End with Spring Boot and PostgreSQL
In this article we are going to create the backend that will be consumed by our Vite/React frontend. Create the project At the Spring Initializr create a project with the following dependencies: Spring Data JPA Spring Web PostgreSQL Driver I'm using Java 21 with Maven, Jar and Spring Boot version 3.3.3. The group name is com.spring, the artifact and name is backend. Generate the project and extract the directory.
十七,Spring Boot 整合 MyBatis 的详细步骤(两种方式)
@ MyBatis 的官方文档:https://mybatis.p2hp.com/ 关于 MyBatis 的学习的详细内容,大家可以移步至:✏️✏️✏️ MyBatis_ChinaRainbowSea的博客-CSDN博客 。 首先,我们创建相关测试的数据库,数据表。如下: CREATE DATABASE `springboot_mybatis` USE `springboot_mybatis` CREATE TABLE `monster` ( `id` int not null auto_increment, `age` int not null, `birthday` DATE DEFAULT NULL, `email` VARCHAR(255) DEFAULT NULL, `gender` CHAR(1) DEFAULT null, `name` VARCHAR(255) DEFAULT NULL, `salary` DOUBLE not NULL, PRIMARY KEY(`id`) ) SELECT * from monster INSERT INTO `monster`...
Show More
loading
Actions
Is this you?
As a journalist, you can create a free Muck Rack account to customize your profile, list your contact preferences, and upload a portfolio of your best work.Get in touch with import
Contact import, search articles and posts on X, monitor coverage, and track replies from one place.
Learn more about Muck Rack