[{"data":1,"prerenderedAt":4273},["ShallowReactive",2],{"post-gpt-sql-integration":3,"rel-gpt-sql-integration":1460,"sib-gpt-sql-integration":4201},{"_path":4,"_dir":5,"_draft":6,"_partial":6,"_locale":7,"title":8,"description":9,"date":10,"layout":11,"subtitle":12,"image":13,"optimized_image":13,"category":14,"tags":15,"author":21,"paginate":6,"body":22,"_type":1454,"_id":1455,"_source":1456,"_file":1457,"_stem":1458,"_extension":1459},"/posts/gpt-sql-integration","posts",false,"","Implementa un analizador de consultas en lenguaje natural para bases de datos SQL con GPT","Aprende a implementar un sistema que convierte consultas en lenguaje natural en sentencias SQL usando OpenAI GPT, con un tutorial paso a paso y ejemplos prácticos.","2025-01-15T11:00:00.000Z","post","Transforma preguntas naturales en consultas SQL automatizadas","/assets/img/uploads/gpt-sql-integration.png","code",[14,16,17,18,19,20],"gpt","openai","sql","ai","nlp","jaimedearcos",{"type":23,"children":24,"toc":1443},"root",[25,37,44,64,70,75,123,136,152,158,163,389,395,400,736,742,747,1098,1104,1109,1168,1174,1179,1360,1366,1384,1390,1395,1402,1437],{"type":26,"tag":27,"props":28,"children":29},"element","blockquote",{},[30],{"type":26,"tag":31,"props":32,"children":33},"p",{},[34],{"type":35,"value":36},"text","Convertir preguntas naturales en consultas SQL de forma automática simplifica la interacción con bases de datos, permitiendo que usuarios sin conocimientos técnicos extraigan datos relevantes. En este tutorial, aprenderás a implementar esta solución utilizando la API de OpenAI GPT.",{"type":26,"tag":38,"props":39,"children":41},"h2",{"id":40},"requisitos-previos",[42],{"type":35,"value":43},"Requisitos Previos",{"type":26,"tag":45,"props":46,"children":47},"ul",{},[48,54,59],{"type":26,"tag":49,"props":50,"children":51},"li",{},[52],{"type":35,"value":53},"Cuenta y clave API de OpenAI",{"type":26,"tag":49,"props":55,"children":56},{},[57],{"type":35,"value":58},"Python instalado en tu entorno",{"type":26,"tag":49,"props":60,"children":61},{},[62],{"type":35,"value":63},"Base de datos SQL (ej.: PostgreSQL, MySQL)",{"type":26,"tag":38,"props":65,"children":67},{"id":66},"paso-1-configuración-del-entorno",[68],{"type":35,"value":69},"Paso 1: Configuración del entorno",{"type":26,"tag":31,"props":71,"children":72},{},[73],{"type":35,"value":74},"Primero, instala las dependencias necesarias:",{"type":26,"tag":76,"props":77,"children":81},"pre",{"className":78,"code":79,"language":80,"meta":7,"style":7},"language-bash shiki shiki-themes github-dark github-light","pip install openai python-dotenv sqlalchemy psycopg2-binary\n","bash",[82],{"type":26,"tag":14,"props":83,"children":84},{"__ignoreMap":7},[85],{"type":26,"tag":86,"props":87,"children":90},"span",{"class":88,"line":89},"line",1,[91,97,103,108,113,118],{"type":26,"tag":86,"props":92,"children":94},{"style":93},"--shiki-default:#B392F0;--shiki-light:#6F42C1",[95],{"type":35,"value":96},"pip",{"type":26,"tag":86,"props":98,"children":100},{"style":99},"--shiki-default:#9ECBFF;--shiki-light:#032F62",[101],{"type":35,"value":102}," install",{"type":26,"tag":86,"props":104,"children":105},{"style":99},[106],{"type":35,"value":107}," openai",{"type":26,"tag":86,"props":109,"children":110},{"style":99},[111],{"type":35,"value":112}," python-dotenv",{"type":26,"tag":86,"props":114,"children":115},{"style":99},[116],{"type":35,"value":117}," sqlalchemy",{"type":26,"tag":86,"props":119,"children":120},{"style":99},[121],{"type":35,"value":122}," psycopg2-binary\n",{"type":26,"tag":31,"props":124,"children":125},{},[126,128,134],{"type":35,"value":127},"Guarda tu clave API en un archivo ",{"type":26,"tag":14,"props":129,"children":131},{"className":130},[],[132],{"type":35,"value":133},".env",{"type":35,"value":135},":",{"type":26,"tag":76,"props":137,"children":141},{"className":138,"code":139,"language":140,"meta":7,"style":7},"language-env shiki shiki-themes github-dark github-light","OPENAI_API_KEY='tu-api-key'\n","env",[142],{"type":26,"tag":14,"props":143,"children":144},{"__ignoreMap":7},[145],{"type":26,"tag":86,"props":146,"children":147},{"class":88,"line":89},[148],{"type":26,"tag":86,"props":149,"children":150},{},[151],{"type":35,"value":139},{"type":26,"tag":38,"props":153,"children":155},{"id":154},"paso-2-conexión-a-la-base-de-datos",[156],{"type":35,"value":157},"Paso 2: Conexión a la base de datos",{"type":26,"tag":31,"props":159,"children":160},{},[161],{"type":35,"value":162},"Utiliza SQLAlchemy para conectarte a tu base de datos:",{"type":26,"tag":76,"props":164,"children":168},{"className":165,"code":166,"language":167,"meta":7,"style":7},"language-python shiki shiki-themes github-dark github-light","from sqlalchemy import create_engine\nfrom sqlalchemy.orm import sessionmaker\nimport os\nfrom dotenv import load_dotenv\n\nload_dotenv()\n\nDATABASE_URL = os.getenv(\"DATABASE_URL\")\nengine = create_engine(DATABASE_URL)\nSession = sessionmaker(bind=engine)\nsession = Session()\n","python",[169],{"type":26,"tag":14,"props":170,"children":171},{"__ignoreMap":7},[172,197,219,232,254,264,273,281,311,338,371],{"type":26,"tag":86,"props":173,"children":174},{"class":88,"line":89},[175,181,187,192],{"type":26,"tag":86,"props":176,"children":178},{"style":177},"--shiki-default:#F97583;--shiki-light:#D73A49",[179],{"type":35,"value":180},"from",{"type":26,"tag":86,"props":182,"children":184},{"style":183},"--shiki-default:#E1E4E8;--shiki-light:#24292E",[185],{"type":35,"value":186}," sqlalchemy ",{"type":26,"tag":86,"props":188,"children":189},{"style":177},[190],{"type":35,"value":191},"import",{"type":26,"tag":86,"props":193,"children":194},{"style":183},[195],{"type":35,"value":196}," create_engine\n",{"type":26,"tag":86,"props":198,"children":200},{"class":88,"line":199},2,[201,205,210,214],{"type":26,"tag":86,"props":202,"children":203},{"style":177},[204],{"type":35,"value":180},{"type":26,"tag":86,"props":206,"children":207},{"style":183},[208],{"type":35,"value":209}," sqlalchemy.orm ",{"type":26,"tag":86,"props":211,"children":212},{"style":177},[213],{"type":35,"value":191},{"type":26,"tag":86,"props":215,"children":216},{"style":183},[217],{"type":35,"value":218}," sessionmaker\n",{"type":26,"tag":86,"props":220,"children":222},{"class":88,"line":221},3,[223,227],{"type":26,"tag":86,"props":224,"children":225},{"style":177},[226],{"type":35,"value":191},{"type":26,"tag":86,"props":228,"children":229},{"style":183},[230],{"type":35,"value":231}," os\n",{"type":26,"tag":86,"props":233,"children":235},{"class":88,"line":234},4,[236,240,245,249],{"type":26,"tag":86,"props":237,"children":238},{"style":177},[239],{"type":35,"value":180},{"type":26,"tag":86,"props":241,"children":242},{"style":183},[243],{"type":35,"value":244}," dotenv ",{"type":26,"tag":86,"props":246,"children":247},{"style":177},[248],{"type":35,"value":191},{"type":26,"tag":86,"props":250,"children":251},{"style":183},[252],{"type":35,"value":253}," load_dotenv\n",{"type":26,"tag":86,"props":255,"children":257},{"class":88,"line":256},5,[258],{"type":26,"tag":86,"props":259,"children":261},{"emptyLinePlaceholder":260},true,[262],{"type":35,"value":263},"\n",{"type":26,"tag":86,"props":265,"children":267},{"class":88,"line":266},6,[268],{"type":26,"tag":86,"props":269,"children":270},{"style":183},[271],{"type":35,"value":272},"load_dotenv()\n",{"type":26,"tag":86,"props":274,"children":276},{"class":88,"line":275},7,[277],{"type":26,"tag":86,"props":278,"children":279},{"emptyLinePlaceholder":260},[280],{"type":35,"value":263},{"type":26,"tag":86,"props":282,"children":284},{"class":88,"line":283},8,[285,291,296,301,306],{"type":26,"tag":86,"props":286,"children":288},{"style":287},"--shiki-default:#79B8FF;--shiki-light:#005CC5",[289],{"type":35,"value":290},"DATABASE_URL",{"type":26,"tag":86,"props":292,"children":293},{"style":177},[294],{"type":35,"value":295}," =",{"type":26,"tag":86,"props":297,"children":298},{"style":183},[299],{"type":35,"value":300}," os.getenv(",{"type":26,"tag":86,"props":302,"children":303},{"style":99},[304],{"type":35,"value":305},"\"DATABASE_URL\"",{"type":26,"tag":86,"props":307,"children":308},{"style":183},[309],{"type":35,"value":310},")\n",{"type":26,"tag":86,"props":312,"children":314},{"class":88,"line":313},9,[315,320,325,330,334],{"type":26,"tag":86,"props":316,"children":317},{"style":183},[318],{"type":35,"value":319},"engine ",{"type":26,"tag":86,"props":321,"children":322},{"style":177},[323],{"type":35,"value":324},"=",{"type":26,"tag":86,"props":326,"children":327},{"style":183},[328],{"type":35,"value":329}," create_engine(",{"type":26,"tag":86,"props":331,"children":332},{"style":287},[333],{"type":35,"value":290},{"type":26,"tag":86,"props":335,"children":336},{"style":183},[337],{"type":35,"value":310},{"type":26,"tag":86,"props":339,"children":341},{"class":88,"line":340},10,[342,347,351,356,362,366],{"type":26,"tag":86,"props":343,"children":344},{"style":183},[345],{"type":35,"value":346},"Session ",{"type":26,"tag":86,"props":348,"children":349},{"style":177},[350],{"type":35,"value":324},{"type":26,"tag":86,"props":352,"children":353},{"style":183},[354],{"type":35,"value":355}," sessionmaker(",{"type":26,"tag":86,"props":357,"children":359},{"style":358},"--shiki-default:#FFAB70;--shiki-light:#E36209",[360],{"type":35,"value":361},"bind",{"type":26,"tag":86,"props":363,"children":364},{"style":177},[365],{"type":35,"value":324},{"type":26,"tag":86,"props":367,"children":368},{"style":183},[369],{"type":35,"value":370},"engine)\n",{"type":26,"tag":86,"props":372,"children":374},{"class":88,"line":373},11,[375,380,384],{"type":26,"tag":86,"props":376,"children":377},{"style":183},[378],{"type":35,"value":379},"session ",{"type":26,"tag":86,"props":381,"children":382},{"style":177},[383],{"type":35,"value":324},{"type":26,"tag":86,"props":385,"children":386},{"style":183},[387],{"type":35,"value":388}," Session()\n",{"type":26,"tag":38,"props":390,"children":392},{"id":391},"paso-3-obtener-esquema-de-la-base-de-datos",[393],{"type":35,"value":394},"Paso 3: Obtener esquema de la base de datos",{"type":26,"tag":31,"props":396,"children":397},{},[398],{"type":35,"value":399},"Genera una descripción del esquema que será utilizada por GPT:",{"type":26,"tag":76,"props":401,"children":403},{"className":165,"code":402,"language":167,"meta":7,"style":7},"from sqlalchemy import inspect\n\ndef get_database_schema(engine):\n    inspector = inspect(engine)\n    schema_description = \"\"\n    for table_name in inspector.get_table_names():\n        schema_description += f\"Table: {table_name}\\n\"\n        for column in inspector.get_columns(table_name):\n            schema_description += f\"- {column['name']} ({column['type']})\\n\"\n        schema_description += \"\\n\"\n    return schema_description\n\nschema_description = get_database_schema(engine)\nprint(schema_description)\n",[404],{"type":26,"tag":14,"props":405,"children":406},{"__ignoreMap":7},[407,427,434,452,469,486,509,552,574,659,683,696,704,722],{"type":26,"tag":86,"props":408,"children":409},{"class":88,"line":89},[410,414,418,422],{"type":26,"tag":86,"props":411,"children":412},{"style":177},[413],{"type":35,"value":180},{"type":26,"tag":86,"props":415,"children":416},{"style":183},[417],{"type":35,"value":186},{"type":26,"tag":86,"props":419,"children":420},{"style":177},[421],{"type":35,"value":191},{"type":26,"tag":86,"props":423,"children":424},{"style":183},[425],{"type":35,"value":426}," inspect\n",{"type":26,"tag":86,"props":428,"children":429},{"class":88,"line":199},[430],{"type":26,"tag":86,"props":431,"children":432},{"emptyLinePlaceholder":260},[433],{"type":35,"value":263},{"type":26,"tag":86,"props":435,"children":436},{"class":88,"line":221},[437,442,447],{"type":26,"tag":86,"props":438,"children":439},{"style":177},[440],{"type":35,"value":441},"def",{"type":26,"tag":86,"props":443,"children":444},{"style":93},[445],{"type":35,"value":446}," get_database_schema",{"type":26,"tag":86,"props":448,"children":449},{"style":183},[450],{"type":35,"value":451},"(engine):\n",{"type":26,"tag":86,"props":453,"children":454},{"class":88,"line":234},[455,460,464],{"type":26,"tag":86,"props":456,"children":457},{"style":183},[458],{"type":35,"value":459},"    inspector ",{"type":26,"tag":86,"props":461,"children":462},{"style":177},[463],{"type":35,"value":324},{"type":26,"tag":86,"props":465,"children":466},{"style":183},[467],{"type":35,"value":468}," inspect(engine)\n",{"type":26,"tag":86,"props":470,"children":471},{"class":88,"line":256},[472,477,481],{"type":26,"tag":86,"props":473,"children":474},{"style":183},[475],{"type":35,"value":476},"    schema_description ",{"type":26,"tag":86,"props":478,"children":479},{"style":177},[480],{"type":35,"value":324},{"type":26,"tag":86,"props":482,"children":483},{"style":99},[484],{"type":35,"value":485}," \"\"\n",{"type":26,"tag":86,"props":487,"children":488},{"class":88,"line":266},[489,494,499,504],{"type":26,"tag":86,"props":490,"children":491},{"style":177},[492],{"type":35,"value":493},"    for",{"type":26,"tag":86,"props":495,"children":496},{"style":183},[497],{"type":35,"value":498}," table_name ",{"type":26,"tag":86,"props":500,"children":501},{"style":177},[502],{"type":35,"value":503},"in",{"type":26,"tag":86,"props":505,"children":506},{"style":183},[507],{"type":35,"value":508}," inspector.get_table_names():\n",{"type":26,"tag":86,"props":510,"children":511},{"class":88,"line":275},[512,517,522,527,532,537,542,547],{"type":26,"tag":86,"props":513,"children":514},{"style":183},[515],{"type":35,"value":516},"        schema_description ",{"type":26,"tag":86,"props":518,"children":519},{"style":177},[520],{"type":35,"value":521},"+=",{"type":26,"tag":86,"props":523,"children":524},{"style":177},[525],{"type":35,"value":526}," f",{"type":26,"tag":86,"props":528,"children":529},{"style":99},[530],{"type":35,"value":531},"\"Table: ",{"type":26,"tag":86,"props":533,"children":534},{"style":287},[535],{"type":35,"value":536},"{",{"type":26,"tag":86,"props":538,"children":539},{"style":183},[540],{"type":35,"value":541},"table_name",{"type":26,"tag":86,"props":543,"children":544},{"style":287},[545],{"type":35,"value":546},"}\\n",{"type":26,"tag":86,"props":548,"children":549},{"style":99},[550],{"type":35,"value":551},"\"\n",{"type":26,"tag":86,"props":553,"children":554},{"class":88,"line":283},[555,560,565,569],{"type":26,"tag":86,"props":556,"children":557},{"style":177},[558],{"type":35,"value":559},"        for",{"type":26,"tag":86,"props":561,"children":562},{"style":183},[563],{"type":35,"value":564}," column ",{"type":26,"tag":86,"props":566,"children":567},{"style":177},[568],{"type":35,"value":503},{"type":26,"tag":86,"props":570,"children":571},{"style":183},[572],{"type":35,"value":573}," inspector.get_columns(table_name):\n",{"type":26,"tag":86,"props":575,"children":576},{"class":88,"line":313},[577,582,586,590,595,599,604,609,614,619,624,628,632,637,641,645,650,655],{"type":26,"tag":86,"props":578,"children":579},{"style":183},[580],{"type":35,"value":581},"            schema_description ",{"type":26,"tag":86,"props":583,"children":584},{"style":177},[585],{"type":35,"value":521},{"type":26,"tag":86,"props":587,"children":588},{"style":177},[589],{"type":35,"value":526},{"type":26,"tag":86,"props":591,"children":592},{"style":99},[593],{"type":35,"value":594},"\"- ",{"type":26,"tag":86,"props":596,"children":597},{"style":287},[598],{"type":35,"value":536},{"type":26,"tag":86,"props":600,"children":601},{"style":183},[602],{"type":35,"value":603},"column[",{"type":26,"tag":86,"props":605,"children":606},{"style":99},[607],{"type":35,"value":608},"'name'",{"type":26,"tag":86,"props":610,"children":611},{"style":183},[612],{"type":35,"value":613},"]",{"type":26,"tag":86,"props":615,"children":616},{"style":287},[617],{"type":35,"value":618},"}",{"type":26,"tag":86,"props":620,"children":621},{"style":99},[622],{"type":35,"value":623}," (",{"type":26,"tag":86,"props":625,"children":626},{"style":287},[627],{"type":35,"value":536},{"type":26,"tag":86,"props":629,"children":630},{"style":183},[631],{"type":35,"value":603},{"type":26,"tag":86,"props":633,"children":634},{"style":99},[635],{"type":35,"value":636},"'type'",{"type":26,"tag":86,"props":638,"children":639},{"style":183},[640],{"type":35,"value":613},{"type":26,"tag":86,"props":642,"children":643},{"style":287},[644],{"type":35,"value":618},{"type":26,"tag":86,"props":646,"children":647},{"style":99},[648],{"type":35,"value":649},")",{"type":26,"tag":86,"props":651,"children":652},{"style":287},[653],{"type":35,"value":654},"\\n",{"type":26,"tag":86,"props":656,"children":657},{"style":99},[658],{"type":35,"value":551},{"type":26,"tag":86,"props":660,"children":661},{"class":88,"line":340},[662,666,670,675,679],{"type":26,"tag":86,"props":663,"children":664},{"style":183},[665],{"type":35,"value":516},{"type":26,"tag":86,"props":667,"children":668},{"style":177},[669],{"type":35,"value":521},{"type":26,"tag":86,"props":671,"children":672},{"style":99},[673],{"type":35,"value":674}," \"",{"type":26,"tag":86,"props":676,"children":677},{"style":287},[678],{"type":35,"value":654},{"type":26,"tag":86,"props":680,"children":681},{"style":99},[682],{"type":35,"value":551},{"type":26,"tag":86,"props":684,"children":685},{"class":88,"line":373},[686,691],{"type":26,"tag":86,"props":687,"children":688},{"style":177},[689],{"type":35,"value":690},"    return",{"type":26,"tag":86,"props":692,"children":693},{"style":183},[694],{"type":35,"value":695}," schema_description\n",{"type":26,"tag":86,"props":697,"children":699},{"class":88,"line":698},12,[700],{"type":26,"tag":86,"props":701,"children":702},{"emptyLinePlaceholder":260},[703],{"type":35,"value":263},{"type":26,"tag":86,"props":705,"children":707},{"class":88,"line":706},13,[708,713,717],{"type":26,"tag":86,"props":709,"children":710},{"style":183},[711],{"type":35,"value":712},"schema_description ",{"type":26,"tag":86,"props":714,"children":715},{"style":177},[716],{"type":35,"value":324},{"type":26,"tag":86,"props":718,"children":719},{"style":183},[720],{"type":35,"value":721}," get_database_schema(engine)\n",{"type":26,"tag":86,"props":723,"children":725},{"class":88,"line":724},14,[726,731],{"type":26,"tag":86,"props":727,"children":728},{"style":287},[729],{"type":35,"value":730},"print",{"type":26,"tag":86,"props":732,"children":733},{"style":183},[734],{"type":35,"value":735},"(schema_description)\n",{"type":26,"tag":38,"props":737,"children":739},{"id":738},"paso-4-preparar-la-consulta-con-gpt",[740],{"type":35,"value":741},"Paso 4: Preparar la consulta con GPT",{"type":26,"tag":31,"props":743,"children":744},{},[745],{"type":35,"value":746},"Utiliza la API de OpenAI para transformar preguntas en consultas SQL, incluyendo el esquema de la base de datos:",{"type":26,"tag":76,"props":748,"children":750},{"className":165,"code":749,"language":167,"meta":7,"style":7},"import openai\nimport os\n\nopenai.api_key = os.getenv(\"OPENAI_API_KEY\")\n\ndef generate_sql(question, schema):\n    response = openai.ChatCompletion.create(\n        model=\"gpt-4\",\n        messages=[\n            {\"role\": \"system\", \"content\": f\"Convierte preguntas en lenguaje natural a consultas SQL. Esquema de la base de datos:\\n{schema}\"},\n            {\"role\": \"user\", \"content\": question}\n        ]\n    )\n    sql_query = response.choices[0].message.content.strip()\n    return sql_query\n\nquery = generate_sql(\"¿Cuántos usuarios se registraron el último mes?\", schema_description)\nprint(query)\n",[751],{"type":26,"tag":14,"props":752,"children":753},{"__ignoreMap":7},[754,766,777,784,809,816,833,850,872,889,960,993,1001,1009,1036,1049,1057,1085],{"type":26,"tag":86,"props":755,"children":756},{"class":88,"line":89},[757,761],{"type":26,"tag":86,"props":758,"children":759},{"style":177},[760],{"type":35,"value":191},{"type":26,"tag":86,"props":762,"children":763},{"style":183},[764],{"type":35,"value":765}," openai\n",{"type":26,"tag":86,"props":767,"children":768},{"class":88,"line":199},[769,773],{"type":26,"tag":86,"props":770,"children":771},{"style":177},[772],{"type":35,"value":191},{"type":26,"tag":86,"props":774,"children":775},{"style":183},[776],{"type":35,"value":231},{"type":26,"tag":86,"props":778,"children":779},{"class":88,"line":221},[780],{"type":26,"tag":86,"props":781,"children":782},{"emptyLinePlaceholder":260},[783],{"type":35,"value":263},{"type":26,"tag":86,"props":785,"children":786},{"class":88,"line":234},[787,792,796,800,805],{"type":26,"tag":86,"props":788,"children":789},{"style":183},[790],{"type":35,"value":791},"openai.api_key ",{"type":26,"tag":86,"props":793,"children":794},{"style":177},[795],{"type":35,"value":324},{"type":26,"tag":86,"props":797,"children":798},{"style":183},[799],{"type":35,"value":300},{"type":26,"tag":86,"props":801,"children":802},{"style":99},[803],{"type":35,"value":804},"\"OPENAI_API_KEY\"",{"type":26,"tag":86,"props":806,"children":807},{"style":183},[808],{"type":35,"value":310},{"type":26,"tag":86,"props":810,"children":811},{"class":88,"line":256},[812],{"type":26,"tag":86,"props":813,"children":814},{"emptyLinePlaceholder":260},[815],{"type":35,"value":263},{"type":26,"tag":86,"props":817,"children":818},{"class":88,"line":266},[819,823,828],{"type":26,"tag":86,"props":820,"children":821},{"style":177},[822],{"type":35,"value":441},{"type":26,"tag":86,"props":824,"children":825},{"style":93},[826],{"type":35,"value":827}," generate_sql",{"type":26,"tag":86,"props":829,"children":830},{"style":183},[831],{"type":35,"value":832},"(question, schema):\n",{"type":26,"tag":86,"props":834,"children":835},{"class":88,"line":275},[836,841,845],{"type":26,"tag":86,"props":837,"children":838},{"style":183},[839],{"type":35,"value":840},"    response ",{"type":26,"tag":86,"props":842,"children":843},{"style":177},[844],{"type":35,"value":324},{"type":26,"tag":86,"props":846,"children":847},{"style":183},[848],{"type":35,"value":849}," openai.ChatCompletion.create(\n",{"type":26,"tag":86,"props":851,"children":852},{"class":88,"line":283},[853,858,862,867],{"type":26,"tag":86,"props":854,"children":855},{"style":358},[856],{"type":35,"value":857},"        model",{"type":26,"tag":86,"props":859,"children":860},{"style":177},[861],{"type":35,"value":324},{"type":26,"tag":86,"props":863,"children":864},{"style":99},[865],{"type":35,"value":866},"\"gpt-4\"",{"type":26,"tag":86,"props":868,"children":869},{"style":183},[870],{"type":35,"value":871},",\n",{"type":26,"tag":86,"props":873,"children":874},{"class":88,"line":313},[875,880,884],{"type":26,"tag":86,"props":876,"children":877},{"style":358},[878],{"type":35,"value":879},"        messages",{"type":26,"tag":86,"props":881,"children":882},{"style":177},[883],{"type":35,"value":324},{"type":26,"tag":86,"props":885,"children":886},{"style":183},[887],{"type":35,"value":888},"[\n",{"type":26,"tag":86,"props":890,"children":891},{"class":88,"line":340},[892,897,902,907,912,917,922,926,931,936,941,946,950,955],{"type":26,"tag":86,"props":893,"children":894},{"style":183},[895],{"type":35,"value":896},"            {",{"type":26,"tag":86,"props":898,"children":899},{"style":99},[900],{"type":35,"value":901},"\"role\"",{"type":26,"tag":86,"props":903,"children":904},{"style":183},[905],{"type":35,"value":906},": ",{"type":26,"tag":86,"props":908,"children":909},{"style":99},[910],{"type":35,"value":911},"\"system\"",{"type":26,"tag":86,"props":913,"children":914},{"style":183},[915],{"type":35,"value":916},", ",{"type":26,"tag":86,"props":918,"children":919},{"style":99},[920],{"type":35,"value":921},"\"content\"",{"type":26,"tag":86,"props":923,"children":924},{"style":183},[925],{"type":35,"value":906},{"type":26,"tag":86,"props":927,"children":928},{"style":177},[929],{"type":35,"value":930},"f",{"type":26,"tag":86,"props":932,"children":933},{"style":99},[934],{"type":35,"value":935},"\"Convierte preguntas en lenguaje natural a consultas SQL. Esquema de la base de datos:",{"type":26,"tag":86,"props":937,"children":938},{"style":287},[939],{"type":35,"value":940},"\\n{",{"type":26,"tag":86,"props":942,"children":943},{"style":183},[944],{"type":35,"value":945},"schema",{"type":26,"tag":86,"props":947,"children":948},{"style":287},[949],{"type":35,"value":618},{"type":26,"tag":86,"props":951,"children":952},{"style":99},[953],{"type":35,"value":954},"\"",{"type":26,"tag":86,"props":956,"children":957},{"style":183},[958],{"type":35,"value":959},"},\n",{"type":26,"tag":86,"props":961,"children":962},{"class":88,"line":373},[963,967,971,975,980,984,988],{"type":26,"tag":86,"props":964,"children":965},{"style":183},[966],{"type":35,"value":896},{"type":26,"tag":86,"props":968,"children":969},{"style":99},[970],{"type":35,"value":901},{"type":26,"tag":86,"props":972,"children":973},{"style":183},[974],{"type":35,"value":906},{"type":26,"tag":86,"props":976,"children":977},{"style":99},[978],{"type":35,"value":979},"\"user\"",{"type":26,"tag":86,"props":981,"children":982},{"style":183},[983],{"type":35,"value":916},{"type":26,"tag":86,"props":985,"children":986},{"style":99},[987],{"type":35,"value":921},{"type":26,"tag":86,"props":989,"children":990},{"style":183},[991],{"type":35,"value":992},": question}\n",{"type":26,"tag":86,"props":994,"children":995},{"class":88,"line":698},[996],{"type":26,"tag":86,"props":997,"children":998},{"style":183},[999],{"type":35,"value":1000},"        ]\n",{"type":26,"tag":86,"props":1002,"children":1003},{"class":88,"line":706},[1004],{"type":26,"tag":86,"props":1005,"children":1006},{"style":183},[1007],{"type":35,"value":1008},"    )\n",{"type":26,"tag":86,"props":1010,"children":1011},{"class":88,"line":724},[1012,1017,1021,1026,1031],{"type":26,"tag":86,"props":1013,"children":1014},{"style":183},[1015],{"type":35,"value":1016},"    sql_query ",{"type":26,"tag":86,"props":1018,"children":1019},{"style":177},[1020],{"type":35,"value":324},{"type":26,"tag":86,"props":1022,"children":1023},{"style":183},[1024],{"type":35,"value":1025}," response.choices[",{"type":26,"tag":86,"props":1027,"children":1028},{"style":287},[1029],{"type":35,"value":1030},"0",{"type":26,"tag":86,"props":1032,"children":1033},{"style":183},[1034],{"type":35,"value":1035},"].message.content.strip()\n",{"type":26,"tag":86,"props":1037,"children":1039},{"class":88,"line":1038},15,[1040,1044],{"type":26,"tag":86,"props":1041,"children":1042},{"style":177},[1043],{"type":35,"value":690},{"type":26,"tag":86,"props":1045,"children":1046},{"style":183},[1047],{"type":35,"value":1048}," sql_query\n",{"type":26,"tag":86,"props":1050,"children":1052},{"class":88,"line":1051},16,[1053],{"type":26,"tag":86,"props":1054,"children":1055},{"emptyLinePlaceholder":260},[1056],{"type":35,"value":263},{"type":26,"tag":86,"props":1058,"children":1060},{"class":88,"line":1059},17,[1061,1066,1070,1075,1080],{"type":26,"tag":86,"props":1062,"children":1063},{"style":183},[1064],{"type":35,"value":1065},"query ",{"type":26,"tag":86,"props":1067,"children":1068},{"style":177},[1069],{"type":35,"value":324},{"type":26,"tag":86,"props":1071,"children":1072},{"style":183},[1073],{"type":35,"value":1074}," generate_sql(",{"type":26,"tag":86,"props":1076,"children":1077},{"style":99},[1078],{"type":35,"value":1079},"\"¿Cuántos usuarios se registraron el último mes?\"",{"type":26,"tag":86,"props":1081,"children":1082},{"style":183},[1083],{"type":35,"value":1084},", schema_description)\n",{"type":26,"tag":86,"props":1086,"children":1088},{"class":88,"line":1087},18,[1089,1093],{"type":26,"tag":86,"props":1090,"children":1091},{"style":287},[1092],{"type":35,"value":730},{"type":26,"tag":86,"props":1094,"children":1095},{"style":183},[1096],{"type":35,"value":1097},"(query)\n",{"type":26,"tag":38,"props":1099,"children":1101},{"id":1100},"paso-5-ejecutar-consultas-generadas",[1102],{"type":35,"value":1103},"Paso 5: Ejecutar consultas generadas",{"type":26,"tag":31,"props":1105,"children":1106},{},[1107],{"type":35,"value":1108},"Ejecuta la consulta generada y obtiene resultados:",{"type":26,"tag":76,"props":1110,"children":1112},{"className":165,"code":1111,"language":167,"meta":7,"style":7},"result = session.execute(query)\nfor row in result:\n    print(row)\n",[1113],{"type":26,"tag":14,"props":1114,"children":1115},{"__ignoreMap":7},[1116,1133,1155],{"type":26,"tag":86,"props":1117,"children":1118},{"class":88,"line":89},[1119,1124,1128],{"type":26,"tag":86,"props":1120,"children":1121},{"style":183},[1122],{"type":35,"value":1123},"result ",{"type":26,"tag":86,"props":1125,"children":1126},{"style":177},[1127],{"type":35,"value":324},{"type":26,"tag":86,"props":1129,"children":1130},{"style":183},[1131],{"type":35,"value":1132}," session.execute(query)\n",{"type":26,"tag":86,"props":1134,"children":1135},{"class":88,"line":199},[1136,1141,1146,1150],{"type":26,"tag":86,"props":1137,"children":1138},{"style":177},[1139],{"type":35,"value":1140},"for",{"type":26,"tag":86,"props":1142,"children":1143},{"style":183},[1144],{"type":35,"value":1145}," row ",{"type":26,"tag":86,"props":1147,"children":1148},{"style":177},[1149],{"type":35,"value":503},{"type":26,"tag":86,"props":1151,"children":1152},{"style":183},[1153],{"type":35,"value":1154}," result:\n",{"type":26,"tag":86,"props":1156,"children":1157},{"class":88,"line":221},[1158,1163],{"type":26,"tag":86,"props":1159,"children":1160},{"style":287},[1161],{"type":35,"value":1162},"    print",{"type":26,"tag":86,"props":1164,"children":1165},{"style":183},[1166],{"type":35,"value":1167},"(row)\n",{"type":26,"tag":38,"props":1169,"children":1171},{"id":1170},"paso-6-manejo-de-errores-y-seguridad",[1172],{"type":35,"value":1173},"Paso 6: Manejo de errores y seguridad",{"type":26,"tag":31,"props":1175,"children":1176},{},[1177],{"type":35,"value":1178},"Para evitar problemas con consultas inseguras o errores, siempre valida las consultas generadas por GPT antes de ejecutarlas directamente:",{"type":26,"tag":76,"props":1180,"children":1182},{"className":165,"code":1181,"language":167,"meta":7,"style":7},"def execute_safe_query(sql_query):\n    try:\n        result = session.execute(sql_query)\n        return result.fetchall()\n    except Exception as e:\n        print(f\"Error al ejecutar consulta: {e}\")\n        return None\n\nresults = execute_safe_query(query)\nprint(results)\n",[1183],{"type":26,"tag":14,"props":1184,"children":1185},{"__ignoreMap":7},[1186,1203,1216,1233,1246,1269,1312,1324,1331,1348],{"type":26,"tag":86,"props":1187,"children":1188},{"class":88,"line":89},[1189,1193,1198],{"type":26,"tag":86,"props":1190,"children":1191},{"style":177},[1192],{"type":35,"value":441},{"type":26,"tag":86,"props":1194,"children":1195},{"style":93},[1196],{"type":35,"value":1197}," execute_safe_query",{"type":26,"tag":86,"props":1199,"children":1200},{"style":183},[1201],{"type":35,"value":1202},"(sql_query):\n",{"type":26,"tag":86,"props":1204,"children":1205},{"class":88,"line":199},[1206,1211],{"type":26,"tag":86,"props":1207,"children":1208},{"style":177},[1209],{"type":35,"value":1210},"    try",{"type":26,"tag":86,"props":1212,"children":1213},{"style":183},[1214],{"type":35,"value":1215},":\n",{"type":26,"tag":86,"props":1217,"children":1218},{"class":88,"line":221},[1219,1224,1228],{"type":26,"tag":86,"props":1220,"children":1221},{"style":183},[1222],{"type":35,"value":1223},"        result ",{"type":26,"tag":86,"props":1225,"children":1226},{"style":177},[1227],{"type":35,"value":324},{"type":26,"tag":86,"props":1229,"children":1230},{"style":183},[1231],{"type":35,"value":1232}," session.execute(sql_query)\n",{"type":26,"tag":86,"props":1234,"children":1235},{"class":88,"line":234},[1236,1241],{"type":26,"tag":86,"props":1237,"children":1238},{"style":177},[1239],{"type":35,"value":1240},"        return",{"type":26,"tag":86,"props":1242,"children":1243},{"style":183},[1244],{"type":35,"value":1245}," result.fetchall()\n",{"type":26,"tag":86,"props":1247,"children":1248},{"class":88,"line":256},[1249,1254,1259,1264],{"type":26,"tag":86,"props":1250,"children":1251},{"style":177},[1252],{"type":35,"value":1253},"    except",{"type":26,"tag":86,"props":1255,"children":1256},{"style":287},[1257],{"type":35,"value":1258}," Exception",{"type":26,"tag":86,"props":1260,"children":1261},{"style":177},[1262],{"type":35,"value":1263}," as",{"type":26,"tag":86,"props":1265,"children":1266},{"style":183},[1267],{"type":35,"value":1268}," e:\n",{"type":26,"tag":86,"props":1270,"children":1271},{"class":88,"line":266},[1272,1277,1282,1286,1291,1295,1300,1304,1308],{"type":26,"tag":86,"props":1273,"children":1274},{"style":287},[1275],{"type":35,"value":1276},"        print",{"type":26,"tag":86,"props":1278,"children":1279},{"style":183},[1280],{"type":35,"value":1281},"(",{"type":26,"tag":86,"props":1283,"children":1284},{"style":177},[1285],{"type":35,"value":930},{"type":26,"tag":86,"props":1287,"children":1288},{"style":99},[1289],{"type":35,"value":1290},"\"Error al ejecutar consulta: ",{"type":26,"tag":86,"props":1292,"children":1293},{"style":287},[1294],{"type":35,"value":536},{"type":26,"tag":86,"props":1296,"children":1297},{"style":183},[1298],{"type":35,"value":1299},"e",{"type":26,"tag":86,"props":1301,"children":1302},{"style":287},[1303],{"type":35,"value":618},{"type":26,"tag":86,"props":1305,"children":1306},{"style":99},[1307],{"type":35,"value":954},{"type":26,"tag":86,"props":1309,"children":1310},{"style":183},[1311],{"type":35,"value":310},{"type":26,"tag":86,"props":1313,"children":1314},{"class":88,"line":275},[1315,1319],{"type":26,"tag":86,"props":1316,"children":1317},{"style":177},[1318],{"type":35,"value":1240},{"type":26,"tag":86,"props":1320,"children":1321},{"style":287},[1322],{"type":35,"value":1323}," None\n",{"type":26,"tag":86,"props":1325,"children":1326},{"class":88,"line":283},[1327],{"type":26,"tag":86,"props":1328,"children":1329},{"emptyLinePlaceholder":260},[1330],{"type":35,"value":263},{"type":26,"tag":86,"props":1332,"children":1333},{"class":88,"line":313},[1334,1339,1343],{"type":26,"tag":86,"props":1335,"children":1336},{"style":183},[1337],{"type":35,"value":1338},"results ",{"type":26,"tag":86,"props":1340,"children":1341},{"style":177},[1342],{"type":35,"value":324},{"type":26,"tag":86,"props":1344,"children":1345},{"style":183},[1346],{"type":35,"value":1347}," execute_safe_query(query)\n",{"type":26,"tag":86,"props":1349,"children":1350},{"class":88,"line":340},[1351,1355],{"type":26,"tag":86,"props":1352,"children":1353},{"style":287},[1354],{"type":35,"value":730},{"type":26,"tag":86,"props":1356,"children":1357},{"style":183},[1358],{"type":35,"value":1359},"(results)\n",{"type":26,"tag":38,"props":1361,"children":1363},{"id":1362},"buenas-prácticas",[1364],{"type":35,"value":1365},"Buenas prácticas",{"type":26,"tag":45,"props":1367,"children":1368},{},[1369,1374,1379],{"type":26,"tag":49,"props":1370,"children":1371},{},[1372],{"type":35,"value":1373},"Siempre revisa o limita el acceso de los usuarios a consultas críticas o sensibles.",{"type":26,"tag":49,"props":1375,"children":1376},{},[1377],{"type":35,"value":1378},"Implementa validaciones adicionales para asegurar la integridad y seguridad de tu base de datos.",{"type":26,"tag":49,"props":1380,"children":1381},{},[1382],{"type":35,"value":1383},"Utiliza tokens y modelos específicos de OpenAI optimizados para tareas SQL.",{"type":26,"tag":38,"props":1385,"children":1387},{"id":1386},"conclusión",[1388],{"type":35,"value":1389},"Conclusión",{"type":26,"tag":31,"props":1391,"children":1392},{},[1393],{"type":35,"value":1394},"Utilizar GPT para transformar consultas en lenguaje natural a SQL facilita enormemente la accesibilidad a los datos. Implementando este sistema, podrás ofrecer una experiencia de usuario más amigable y eficiente.",{"type":26,"tag":1396,"props":1397,"children":1399},"h1",{"id":1398},"recursos-adicionales",[1400],{"type":35,"value":1401},"Recursos adicionales",{"type":26,"tag":45,"props":1403,"children":1404},{},[1405,1417,1427],{"type":26,"tag":49,"props":1406,"children":1407},{},[1408],{"type":26,"tag":1409,"props":1410,"children":1414},"a",{"href":1411,"rel":1412},"https://platform.openai.com/docs/api-reference",[1413],"nofollow",[1415],{"type":35,"value":1416},"Documentación API OpenAI",{"type":26,"tag":49,"props":1418,"children":1419},{},[1420],{"type":26,"tag":1409,"props":1421,"children":1424},{"href":1422,"rel":1423},"https://docs.sqlalchemy.org/en/20/",[1413],[1425],{"type":35,"value":1426},"SQLAlchemy ORM Documentation",{"type":26,"tag":49,"props":1428,"children":1429},{},[1430],{"type":26,"tag":1409,"props":1431,"children":1434},{"href":1432,"rel":1433},"https://pypi.org/project/python-dotenv/",[1413],[1435],{"type":35,"value":1436},"Python Dotenv",{"type":26,"tag":1438,"props":1439,"children":1440},"style",{},[1441],{"type":35,"value":1442},"html .default .shiki span {color: var(--shiki-default);background: var(--shiki-default-bg);font-style: var(--shiki-default-font-style);font-weight: var(--shiki-default-font-weight);text-decoration: var(--shiki-default-text-decoration);}html .shiki span {color: var(--shiki-default);background: var(--shiki-default-bg);font-style: var(--shiki-default-font-style);font-weight: var(--shiki-default-font-weight);text-decoration: var(--shiki-default-text-decoration);}html .light .shiki span {color: var(--shiki-light);background: var(--shiki-light-bg);font-style: var(--shiki-light-font-style);font-weight: var(--shiki-light-font-weight);text-decoration: var(--shiki-light-text-decoration);}html.light .shiki span {color: var(--shiki-light);background: var(--shiki-light-bg);font-style: var(--shiki-light-font-style);font-weight: var(--shiki-light-font-weight);text-decoration: var(--shiki-light-text-decoration);}",{"title":7,"searchDepth":199,"depth":199,"links":1444},[1445,1446,1447,1448,1449,1450,1451,1452,1453],{"id":40,"depth":199,"text":43},{"id":66,"depth":199,"text":69},{"id":154,"depth":199,"text":157},{"id":391,"depth":199,"text":394},{"id":738,"depth":199,"text":741},{"id":1100,"depth":199,"text":1103},{"id":1170,"depth":199,"text":1173},{"id":1362,"depth":199,"text":1365},{"id":1386,"depth":199,"text":1389},"markdown","content:posts:gpt-sql-integration.md","content","posts/gpt-sql-integration.md","posts/gpt-sql-integration","md",[1461,2371,3191],{"_path":1462,"_dir":5,"_draft":6,"_partial":6,"_locale":7,"title":1463,"description":1464,"date":1465,"layout":11,"subtitle":1466,"image":1467,"optimized_image":1467,"category":14,"tags":1468,"author":21,"paginate":6,"body":1473,"_type":1454,"_id":2368,"_source":1456,"_file":2369,"_stem":2370,"_extension":1459},"/posts/java-security-best-practices","Java Security Best Practices: Preventing Vulnerabilities and Threats","Explore essential security strategies for Java applications, addressing common vulnerabilities identified by OWASP Top 10 with practical examples.","2024-08-15T11:00:00.000Z","Practical Strategies to Safeguard Your Java Applications","/assets/img/uploads/java-security-best-practices.png",[14,1469,1470,1471,1472],"java","security","owasp","cybersecurity",{"type":23,"children":1474,"toc":2356},[1475,1483,1489,1494,1548,1553,1559,1564,1687,1692,1698,1703,1806,1812,1817,1940,1945,1951,1956,1981,1986,1992,1997,2013,2018,2024,2029,2112,2117,2123,2128,2248,2253,2259,2264,2297,2302,2308,2313,2319,2352],{"type":26,"tag":27,"props":1476,"children":1477},{},[1478],{"type":26,"tag":31,"props":1479,"children":1480},{},[1481],{"type":35,"value":1482},"Security is critical in software development. Java applications, like all software, face numerous potential vulnerabilities. In this article, we will explore essential security best practices, referencing the OWASP Top 10, and providing practical Java examples to help you protect your applications effectively.",{"type":26,"tag":38,"props":1484,"children":1486},{"id":1485},"understanding-owasp-top-10",[1487],{"type":35,"value":1488},"Understanding OWASP Top 10",{"type":26,"tag":31,"props":1490,"children":1491},{},[1492],{"type":35,"value":1493},"The OWASP Top 10 outlines the most critical web application security risks:",{"type":26,"tag":1495,"props":1496,"children":1497},"ol",{},[1498,1503,1508,1513,1518,1523,1528,1533,1538,1543],{"type":26,"tag":49,"props":1499,"children":1500},{},[1501],{"type":35,"value":1502},"Injection",{"type":26,"tag":49,"props":1504,"children":1505},{},[1506],{"type":35,"value":1507},"Broken Authentication",{"type":26,"tag":49,"props":1509,"children":1510},{},[1511],{"type":35,"value":1512},"Sensitive Data Exposure",{"type":26,"tag":49,"props":1514,"children":1515},{},[1516],{"type":35,"value":1517},"XML External Entities (XXE)",{"type":26,"tag":49,"props":1519,"children":1520},{},[1521],{"type":35,"value":1522},"Broken Access Control",{"type":26,"tag":49,"props":1524,"children":1525},{},[1526],{"type":35,"value":1527},"Security Misconfiguration",{"type":26,"tag":49,"props":1529,"children":1530},{},[1531],{"type":35,"value":1532},"Cross-Site Scripting (XSS)",{"type":26,"tag":49,"props":1534,"children":1535},{},[1536],{"type":35,"value":1537},"Insecure Deserialization",{"type":26,"tag":49,"props":1539,"children":1540},{},[1541],{"type":35,"value":1542},"Using Components with Known Vulnerabilities",{"type":26,"tag":49,"props":1544,"children":1545},{},[1546],{"type":35,"value":1547},"Insufficient Logging and Monitoring",{"type":26,"tag":31,"props":1549,"children":1550},{},[1551],{"type":35,"value":1552},"Let's delve into practical strategies and Java implementations for some of these threats.",{"type":26,"tag":38,"props":1554,"children":1556},{"id":1555},"_1-injection-prevention",[1557],{"type":35,"value":1558},"1. Injection Prevention",{"type":26,"tag":31,"props":1560,"children":1561},{},[1562],{"type":35,"value":1563},"Use Prepared Statements and parameterized queries:",{"type":26,"tag":76,"props":1565,"children":1568},{"className":1566,"code":1567,"language":1469,"meta":7,"style":7},"language-java shiki shiki-themes github-dark github-light","PreparedStatement stmt = connection.prepareStatement(\"SELECT * FROM users WHERE username=? AND password=?\");\nstmt.setString(1, username);\nstmt.setString(2, password);\nResultSet rs = stmt.executeQuery();\n",[1569],{"type":26,"tag":14,"props":1570,"children":1571},{"__ignoreMap":7},[1572,1608,1635,1660],{"type":26,"tag":86,"props":1573,"children":1574},{"class":88,"line":89},[1575,1580,1584,1589,1594,1598,1603],{"type":26,"tag":86,"props":1576,"children":1577},{"style":183},[1578],{"type":35,"value":1579},"PreparedStatement stmt ",{"type":26,"tag":86,"props":1581,"children":1582},{"style":177},[1583],{"type":35,"value":324},{"type":26,"tag":86,"props":1585,"children":1586},{"style":183},[1587],{"type":35,"value":1588}," connection.",{"type":26,"tag":86,"props":1590,"children":1591},{"style":93},[1592],{"type":35,"value":1593},"prepareStatement",{"type":26,"tag":86,"props":1595,"children":1596},{"style":183},[1597],{"type":35,"value":1281},{"type":26,"tag":86,"props":1599,"children":1600},{"style":99},[1601],{"type":35,"value":1602},"\"SELECT * FROM users WHERE username=? AND password=?\"",{"type":26,"tag":86,"props":1604,"children":1605},{"style":183},[1606],{"type":35,"value":1607},");\n",{"type":26,"tag":86,"props":1609,"children":1610},{"class":88,"line":199},[1611,1616,1621,1625,1630],{"type":26,"tag":86,"props":1612,"children":1613},{"style":183},[1614],{"type":35,"value":1615},"stmt.",{"type":26,"tag":86,"props":1617,"children":1618},{"style":93},[1619],{"type":35,"value":1620},"setString",{"type":26,"tag":86,"props":1622,"children":1623},{"style":183},[1624],{"type":35,"value":1281},{"type":26,"tag":86,"props":1626,"children":1627},{"style":287},[1628],{"type":35,"value":1629},"1",{"type":26,"tag":86,"props":1631,"children":1632},{"style":183},[1633],{"type":35,"value":1634},", username);\n",{"type":26,"tag":86,"props":1636,"children":1637},{"class":88,"line":221},[1638,1642,1646,1650,1655],{"type":26,"tag":86,"props":1639,"children":1640},{"style":183},[1641],{"type":35,"value":1615},{"type":26,"tag":86,"props":1643,"children":1644},{"style":93},[1645],{"type":35,"value":1620},{"type":26,"tag":86,"props":1647,"children":1648},{"style":183},[1649],{"type":35,"value":1281},{"type":26,"tag":86,"props":1651,"children":1652},{"style":287},[1653],{"type":35,"value":1654},"2",{"type":26,"tag":86,"props":1656,"children":1657},{"style":183},[1658],{"type":35,"value":1659},", password);\n",{"type":26,"tag":86,"props":1661,"children":1662},{"class":88,"line":234},[1663,1668,1672,1677,1682],{"type":26,"tag":86,"props":1664,"children":1665},{"style":183},[1666],{"type":35,"value":1667},"ResultSet rs ",{"type":26,"tag":86,"props":1669,"children":1670},{"style":177},[1671],{"type":35,"value":324},{"type":26,"tag":86,"props":1673,"children":1674},{"style":183},[1675],{"type":35,"value":1676}," stmt.",{"type":26,"tag":86,"props":1678,"children":1679},{"style":93},[1680],{"type":35,"value":1681},"executeQuery",{"type":26,"tag":86,"props":1683,"children":1684},{"style":183},[1685],{"type":35,"value":1686},"();\n",{"type":26,"tag":31,"props":1688,"children":1689},{},[1690],{"type":35,"value":1691},"This approach prevents SQL injection by ensuring that input data is treated as data, not executable code.",{"type":26,"tag":38,"props":1693,"children":1695},{"id":1694},"_2-secure-authentication",[1696],{"type":35,"value":1697},"2. Secure Authentication",{"type":26,"tag":31,"props":1699,"children":1700},{},[1701],{"type":35,"value":1702},"Implement robust authentication using secure password storage (bcrypt or Argon2):",{"type":26,"tag":76,"props":1704,"children":1706},{"className":1566,"code":1705,"language":1469,"meta":7,"style":7},"import org.springframework.security.crypto.bcrypt.BCrypt;\n\nString hashedPassword = BCrypt.hashpw(password, BCrypt.gensalt());\nif (BCrypt.checkpw(password, hashedPassword)) {\n    // authentication successful\n}\n",[1707],{"type":26,"tag":14,"props":1708,"children":1709},{"__ignoreMap":7},[1710,1722,1729,1766,1789,1798],{"type":26,"tag":86,"props":1711,"children":1712},{"class":88,"line":89},[1713,1717],{"type":26,"tag":86,"props":1714,"children":1715},{"style":177},[1716],{"type":35,"value":191},{"type":26,"tag":86,"props":1718,"children":1719},{"style":183},[1720],{"type":35,"value":1721}," org.springframework.security.crypto.bcrypt.BCrypt;\n",{"type":26,"tag":86,"props":1723,"children":1724},{"class":88,"line":199},[1725],{"type":26,"tag":86,"props":1726,"children":1727},{"emptyLinePlaceholder":260},[1728],{"type":35,"value":263},{"type":26,"tag":86,"props":1730,"children":1731},{"class":88,"line":221},[1732,1737,1741,1746,1751,1756,1761],{"type":26,"tag":86,"props":1733,"children":1734},{"style":183},[1735],{"type":35,"value":1736},"String hashedPassword ",{"type":26,"tag":86,"props":1738,"children":1739},{"style":177},[1740],{"type":35,"value":324},{"type":26,"tag":86,"props":1742,"children":1743},{"style":183},[1744],{"type":35,"value":1745}," BCrypt.",{"type":26,"tag":86,"props":1747,"children":1748},{"style":93},[1749],{"type":35,"value":1750},"hashpw",{"type":26,"tag":86,"props":1752,"children":1753},{"style":183},[1754],{"type":35,"value":1755},"(password, BCrypt.",{"type":26,"tag":86,"props":1757,"children":1758},{"style":93},[1759],{"type":35,"value":1760},"gensalt",{"type":26,"tag":86,"props":1762,"children":1763},{"style":183},[1764],{"type":35,"value":1765},"());\n",{"type":26,"tag":86,"props":1767,"children":1768},{"class":88,"line":234},[1769,1774,1779,1784],{"type":26,"tag":86,"props":1770,"children":1771},{"style":177},[1772],{"type":35,"value":1773},"if",{"type":26,"tag":86,"props":1775,"children":1776},{"style":183},[1777],{"type":35,"value":1778}," (BCrypt.",{"type":26,"tag":86,"props":1780,"children":1781},{"style":93},[1782],{"type":35,"value":1783},"checkpw",{"type":26,"tag":86,"props":1785,"children":1786},{"style":183},[1787],{"type":35,"value":1788},"(password, hashedPassword)) {\n",{"type":26,"tag":86,"props":1790,"children":1791},{"class":88,"line":256},[1792],{"type":26,"tag":86,"props":1793,"children":1795},{"style":1794},"--shiki-default:#6A737D;--shiki-light:#6A737D",[1796],{"type":35,"value":1797},"    // authentication successful\n",{"type":26,"tag":86,"props":1799,"children":1800},{"class":88,"line":266},[1801],{"type":26,"tag":86,"props":1802,"children":1803},{"style":183},[1804],{"type":35,"value":1805},"}\n",{"type":26,"tag":38,"props":1807,"children":1809},{"id":1808},"_3-sensitive-data-exposure",[1810],{"type":35,"value":1811},"3. Sensitive Data Exposure",{"type":26,"tag":31,"props":1813,"children":1814},{},[1815],{"type":35,"value":1816},"Use encryption for sensitive data storage:",{"type":26,"tag":76,"props":1818,"children":1820},{"className":1566,"code":1819,"language":1469,"meta":7,"style":7},"Cipher cipher = Cipher.getInstance(\"AES/GCM/NoPadding\");\nSecretKey key = generateSecretKey();\ncipher.init(Cipher.ENCRYPT_MODE, key);\nbyte[] encryptedData = cipher.doFinal(plainData.getBytes(StandardCharsets.UTF_8));\n",[1821],{"type":26,"tag":14,"props":1822,"children":1823},{"__ignoreMap":7},[1824,1859,1880,1898],{"type":26,"tag":86,"props":1825,"children":1826},{"class":88,"line":89},[1827,1832,1836,1841,1846,1850,1855],{"type":26,"tag":86,"props":1828,"children":1829},{"style":183},[1830],{"type":35,"value":1831},"Cipher cipher ",{"type":26,"tag":86,"props":1833,"children":1834},{"style":177},[1835],{"type":35,"value":324},{"type":26,"tag":86,"props":1837,"children":1838},{"style":183},[1839],{"type":35,"value":1840}," Cipher.",{"type":26,"tag":86,"props":1842,"children":1843},{"style":93},[1844],{"type":35,"value":1845},"getInstance",{"type":26,"tag":86,"props":1847,"children":1848},{"style":183},[1849],{"type":35,"value":1281},{"type":26,"tag":86,"props":1851,"children":1852},{"style":99},[1853],{"type":35,"value":1854},"\"AES/GCM/NoPadding\"",{"type":26,"tag":86,"props":1856,"children":1857},{"style":183},[1858],{"type":35,"value":1607},{"type":26,"tag":86,"props":1860,"children":1861},{"class":88,"line":199},[1862,1867,1871,1876],{"type":26,"tag":86,"props":1863,"children":1864},{"style":183},[1865],{"type":35,"value":1866},"SecretKey key ",{"type":26,"tag":86,"props":1868,"children":1869},{"style":177},[1870],{"type":35,"value":324},{"type":26,"tag":86,"props":1872,"children":1873},{"style":93},[1874],{"type":35,"value":1875}," generateSecretKey",{"type":26,"tag":86,"props":1877,"children":1878},{"style":183},[1879],{"type":35,"value":1686},{"type":26,"tag":86,"props":1881,"children":1882},{"class":88,"line":221},[1883,1888,1893],{"type":26,"tag":86,"props":1884,"children":1885},{"style":183},[1886],{"type":35,"value":1887},"cipher.",{"type":26,"tag":86,"props":1889,"children":1890},{"style":93},[1891],{"type":35,"value":1892},"init",{"type":26,"tag":86,"props":1894,"children":1895},{"style":183},[1896],{"type":35,"value":1897},"(Cipher.ENCRYPT_MODE, key);\n",{"type":26,"tag":86,"props":1899,"children":1900},{"class":88,"line":234},[1901,1906,1911,1915,1920,1925,1930,1935],{"type":26,"tag":86,"props":1902,"children":1903},{"style":177},[1904],{"type":35,"value":1905},"byte",{"type":26,"tag":86,"props":1907,"children":1908},{"style":183},[1909],{"type":35,"value":1910},"[] encryptedData ",{"type":26,"tag":86,"props":1912,"children":1913},{"style":177},[1914],{"type":35,"value":324},{"type":26,"tag":86,"props":1916,"children":1917},{"style":183},[1918],{"type":35,"value":1919}," cipher.",{"type":26,"tag":86,"props":1921,"children":1922},{"style":93},[1923],{"type":35,"value":1924},"doFinal",{"type":26,"tag":86,"props":1926,"children":1927},{"style":183},[1928],{"type":35,"value":1929},"(plainData.",{"type":26,"tag":86,"props":1931,"children":1932},{"style":93},[1933],{"type":35,"value":1934},"getBytes",{"type":26,"tag":86,"props":1936,"children":1937},{"style":183},[1938],{"type":35,"value":1939},"(StandardCharsets.UTF_8));\n",{"type":26,"tag":31,"props":1941,"children":1942},{},[1943],{"type":35,"value":1944},"Always encrypt data at rest and in transit (use HTTPS).",{"type":26,"tag":38,"props":1946,"children":1948},{"id":1947},"_4-security-misconfiguration",[1949],{"type":35,"value":1950},"4. Security Misconfiguration",{"type":26,"tag":31,"props":1952,"children":1953},{},[1954],{"type":35,"value":1955},"Adopt secure defaults, disable debugging, and avoid detailed error messages:",{"type":26,"tag":76,"props":1957,"children":1961},{"className":1958,"code":1959,"language":1960,"meta":7,"style":7},"language-properties shiki shiki-themes github-dark github-light","server.error.include-stacktrace=never\nserver.error.include-message=never\n","properties",[1962],{"type":26,"tag":14,"props":1963,"children":1964},{"__ignoreMap":7},[1965,1973],{"type":26,"tag":86,"props":1966,"children":1967},{"class":88,"line":89},[1968],{"type":26,"tag":86,"props":1969,"children":1970},{},[1971],{"type":35,"value":1972},"server.error.include-stacktrace=never\n",{"type":26,"tag":86,"props":1974,"children":1975},{"class":88,"line":199},[1976],{"type":26,"tag":86,"props":1977,"children":1978},{},[1979],{"type":35,"value":1980},"server.error.include-message=never\n",{"type":26,"tag":31,"props":1982,"children":1983},{},[1984],{"type":35,"value":1985},"Review and secure your Java application configuration regularly.",{"type":26,"tag":38,"props":1987,"children":1989},{"id":1988},"_5-cross-site-scripting-xss",[1990],{"type":35,"value":1991},"5. Cross-Site Scripting (XSS)",{"type":26,"tag":31,"props":1993,"children":1994},{},[1995],{"type":35,"value":1996},"Utilize proper encoding or frameworks that prevent XSS by default, such as Thymeleaf:",{"type":26,"tag":76,"props":1998,"children":2002},{"className":1999,"code":2000,"language":2001,"meta":7,"style":7},"language-html shiki shiki-themes github-dark github-light","\u003Cp th:text=\"${userInput}\">\u003C/p>\n","html",[2003],{"type":26,"tag":14,"props":2004,"children":2005},{"__ignoreMap":7},[2006],{"type":26,"tag":86,"props":2007,"children":2008},{"class":88,"line":89},[2009],{"type":26,"tag":86,"props":2010,"children":2011},{},[2012],{"type":35,"value":2000},{"type":26,"tag":31,"props":2014,"children":2015},{},[2016],{"type":35,"value":2017},"Avoid directly inserting user inputs into HTML without proper sanitization or encoding.",{"type":26,"tag":38,"props":2019,"children":2021},{"id":2020},"_6-insecure-deserialization",[2022],{"type":35,"value":2023},"6. Insecure Deserialization",{"type":26,"tag":31,"props":2025,"children":2026},{},[2027],{"type":35,"value":2028},"Limit deserialization to trusted sources only:",{"type":26,"tag":76,"props":2030,"children":2032},{"className":1566,"code":2031,"language":1469,"meta":7,"style":7},"ObjectInputStream ois = new ObjectInputStream(new FileInputStream(\"trusted_data.ser\"));\nMyObject obj = (MyObject) ois.readObject();\n",[2033],{"type":26,"tag":14,"props":2034,"children":2035},{"__ignoreMap":7},[2036,2086],{"type":26,"tag":86,"props":2037,"children":2038},{"class":88,"line":89},[2039,2044,2048,2053,2058,2062,2067,2072,2076,2081],{"type":26,"tag":86,"props":2040,"children":2041},{"style":183},[2042],{"type":35,"value":2043},"ObjectInputStream ois ",{"type":26,"tag":86,"props":2045,"children":2046},{"style":177},[2047],{"type":35,"value":324},{"type":26,"tag":86,"props":2049,"children":2050},{"style":177},[2051],{"type":35,"value":2052}," new",{"type":26,"tag":86,"props":2054,"children":2055},{"style":93},[2056],{"type":35,"value":2057}," ObjectInputStream",{"type":26,"tag":86,"props":2059,"children":2060},{"style":183},[2061],{"type":35,"value":1281},{"type":26,"tag":86,"props":2063,"children":2064},{"style":177},[2065],{"type":35,"value":2066},"new",{"type":26,"tag":86,"props":2068,"children":2069},{"style":93},[2070],{"type":35,"value":2071}," FileInputStream",{"type":26,"tag":86,"props":2073,"children":2074},{"style":183},[2075],{"type":35,"value":1281},{"type":26,"tag":86,"props":2077,"children":2078},{"style":99},[2079],{"type":35,"value":2080},"\"trusted_data.ser\"",{"type":26,"tag":86,"props":2082,"children":2083},{"style":183},[2084],{"type":35,"value":2085},"));\n",{"type":26,"tag":86,"props":2087,"children":2088},{"class":88,"line":199},[2089,2094,2098,2103,2108],{"type":26,"tag":86,"props":2090,"children":2091},{"style":183},[2092],{"type":35,"value":2093},"MyObject obj ",{"type":26,"tag":86,"props":2095,"children":2096},{"style":177},[2097],{"type":35,"value":324},{"type":26,"tag":86,"props":2099,"children":2100},{"style":183},[2101],{"type":35,"value":2102}," (MyObject) ois.",{"type":26,"tag":86,"props":2104,"children":2105},{"style":93},[2106],{"type":35,"value":2107},"readObject",{"type":26,"tag":86,"props":2109,"children":2110},{"style":183},[2111],{"type":35,"value":1686},{"type":26,"tag":31,"props":2113,"children":2114},{},[2115],{"type":35,"value":2116},"Always validate deserialized data.",{"type":26,"tag":38,"props":2118,"children":2120},{"id":2119},"_7-component-vulnerabilities",[2121],{"type":35,"value":2122},"7. Component Vulnerabilities",{"type":26,"tag":31,"props":2124,"children":2125},{},[2126],{"type":35,"value":2127},"Regularly update libraries and dependencies, and use tools like OWASP Dependency-Check to identify vulnerabilities:",{"type":26,"tag":76,"props":2129,"children":2133},{"className":2130,"code":2131,"language":2132,"meta":7,"style":7},"language-xml shiki shiki-themes github-dark github-light","\u003Cplugin>\n    \u003CgroupId>org.owasp\u003C/groupId>\n    \u003CartifactId>dependency-check-maven\u003C/artifactId>\n    \u003Cversion>9.0.9\u003C/version>\n\u003C/plugin>\n","xml",[2134],{"type":26,"tag":14,"props":2135,"children":2136},{"__ignoreMap":7},[2137,2156,2182,2207,2232],{"type":26,"tag":86,"props":2138,"children":2139},{"class":88,"line":89},[2140,2145,2151],{"type":26,"tag":86,"props":2141,"children":2142},{"style":183},[2143],{"type":35,"value":2144},"\u003C",{"type":26,"tag":86,"props":2146,"children":2148},{"style":2147},"--shiki-default:#85E89D;--shiki-light:#22863A",[2149],{"type":35,"value":2150},"plugin",{"type":26,"tag":86,"props":2152,"children":2153},{"style":183},[2154],{"type":35,"value":2155},">\n",{"type":26,"tag":86,"props":2157,"children":2158},{"class":88,"line":199},[2159,2164,2169,2174,2178],{"type":26,"tag":86,"props":2160,"children":2161},{"style":183},[2162],{"type":35,"value":2163},"    \u003C",{"type":26,"tag":86,"props":2165,"children":2166},{"style":2147},[2167],{"type":35,"value":2168},"groupId",{"type":26,"tag":86,"props":2170,"children":2171},{"style":183},[2172],{"type":35,"value":2173},">org.owasp\u003C/",{"type":26,"tag":86,"props":2175,"children":2176},{"style":2147},[2177],{"type":35,"value":2168},{"type":26,"tag":86,"props":2179,"children":2180},{"style":183},[2181],{"type":35,"value":2155},{"type":26,"tag":86,"props":2183,"children":2184},{"class":88,"line":221},[2185,2189,2194,2199,2203],{"type":26,"tag":86,"props":2186,"children":2187},{"style":183},[2188],{"type":35,"value":2163},{"type":26,"tag":86,"props":2190,"children":2191},{"style":2147},[2192],{"type":35,"value":2193},"artifactId",{"type":26,"tag":86,"props":2195,"children":2196},{"style":183},[2197],{"type":35,"value":2198},">dependency-check-maven\u003C/",{"type":26,"tag":86,"props":2200,"children":2201},{"style":2147},[2202],{"type":35,"value":2193},{"type":26,"tag":86,"props":2204,"children":2205},{"style":183},[2206],{"type":35,"value":2155},{"type":26,"tag":86,"props":2208,"children":2209},{"class":88,"line":234},[2210,2214,2219,2224,2228],{"type":26,"tag":86,"props":2211,"children":2212},{"style":183},[2213],{"type":35,"value":2163},{"type":26,"tag":86,"props":2215,"children":2216},{"style":2147},[2217],{"type":35,"value":2218},"version",{"type":26,"tag":86,"props":2220,"children":2221},{"style":183},[2222],{"type":35,"value":2223},">9.0.9\u003C/",{"type":26,"tag":86,"props":2225,"children":2226},{"style":2147},[2227],{"type":35,"value":2218},{"type":26,"tag":86,"props":2229,"children":2230},{"style":183},[2231],{"type":35,"value":2155},{"type":26,"tag":86,"props":2233,"children":2234},{"class":88,"line":256},[2235,2240,2244],{"type":26,"tag":86,"props":2236,"children":2237},{"style":183},[2238],{"type":35,"value":2239},"\u003C/",{"type":26,"tag":86,"props":2241,"children":2242},{"style":2147},[2243],{"type":35,"value":2150},{"type":26,"tag":86,"props":2245,"children":2246},{"style":183},[2247],{"type":35,"value":2155},{"type":26,"tag":31,"props":2249,"children":2250},{},[2251],{"type":35,"value":2252},"Execute dependency checks regularly in your CI/CD pipeline.",{"type":26,"tag":38,"props":2254,"children":2256},{"id":2255},"_8-logging-and-monitoring",[2257],{"type":35,"value":2258},"8. Logging and Monitoring",{"type":26,"tag":31,"props":2260,"children":2261},{},[2262],{"type":35,"value":2263},"Implement comprehensive logging and monitoring to detect and respond to security incidents:",{"type":26,"tag":76,"props":2265,"children":2267},{"className":1566,"code":2266,"language":1469,"meta":7,"style":7},"logger.warn(\"Failed login attempt for user: {}\", username);\n",[2268],{"type":26,"tag":14,"props":2269,"children":2270},{"__ignoreMap":7},[2271],{"type":26,"tag":86,"props":2272,"children":2273},{"class":88,"line":89},[2274,2279,2284,2288,2293],{"type":26,"tag":86,"props":2275,"children":2276},{"style":183},[2277],{"type":35,"value":2278},"logger.",{"type":26,"tag":86,"props":2280,"children":2281},{"style":93},[2282],{"type":35,"value":2283},"warn",{"type":26,"tag":86,"props":2285,"children":2286},{"style":183},[2287],{"type":35,"value":1281},{"type":26,"tag":86,"props":2289,"children":2290},{"style":99},[2291],{"type":35,"value":2292},"\"Failed login attempt for user: {}\"",{"type":26,"tag":86,"props":2294,"children":2295},{"style":183},[2296],{"type":35,"value":1634},{"type":26,"tag":31,"props":2298,"children":2299},{},[2300],{"type":35,"value":2301},"Aggregate logs centrally, and set up alerts for suspicious activities.",{"type":26,"tag":38,"props":2303,"children":2305},{"id":2304},"conclusion",[2306],{"type":35,"value":2307},"Conclusion",{"type":26,"tag":31,"props":2309,"children":2310},{},[2311],{"type":35,"value":2312},"Adopting these best practices can greatly enhance the security posture of your Java applications. Stay proactive by regularly reviewing security measures, updating dependencies, and monitoring your systems. Security is a continuous process, not a one-time setup.",{"type":26,"tag":1396,"props":2314,"children":2316},{"id":2315},"further-reading",[2317],{"type":35,"value":2318},"Further Reading",{"type":26,"tag":45,"props":2320,"children":2321},{},[2322,2332,2342],{"type":26,"tag":49,"props":2323,"children":2324},{},[2325],{"type":26,"tag":1409,"props":2326,"children":2329},{"href":2327,"rel":2328},"https://owasp.org/www-project-top-ten/",[1413],[2330],{"type":35,"value":2331},"OWASP Top 10",{"type":26,"tag":49,"props":2333,"children":2334},{},[2335],{"type":26,"tag":1409,"props":2336,"children":2339},{"href":2337,"rel":2338},"https://spring.io/projects/spring-security",[1413],[2340],{"type":35,"value":2341},"Spring Security",{"type":26,"tag":49,"props":2343,"children":2344},{},[2345],{"type":26,"tag":1409,"props":2346,"children":2349},{"href":2347,"rel":2348},"https://owasp.org/www-project-dependency-check/",[1413],[2350],{"type":35,"value":2351},"OWASP Dependency Check",{"type":26,"tag":1438,"props":2353,"children":2354},{},[2355],{"type":35,"value":1442},{"title":7,"searchDepth":199,"depth":199,"links":2357},[2358,2359,2360,2361,2362,2363,2364,2365,2366,2367],{"id":1485,"depth":199,"text":1488},{"id":1555,"depth":199,"text":1558},{"id":1694,"depth":199,"text":1697},{"id":1808,"depth":199,"text":1811},{"id":1947,"depth":199,"text":1950},{"id":1988,"depth":199,"text":1991},{"id":2020,"depth":199,"text":2023},{"id":2119,"depth":199,"text":2122},{"id":2255,"depth":199,"text":2258},{"id":2304,"depth":199,"text":2307},"content:posts:java-security-best-practices.md","posts/java-security-best-practices.md","posts/java-security-best-practices",{"_path":2372,"_dir":5,"_draft":6,"_partial":6,"_locale":7,"title":2373,"description":2374,"date":2375,"layout":11,"subtitle":2376,"image":2377,"optimized_image":2377,"category":14,"tags":2378,"author":21,"paginate":6,"body":2382,"_type":1454,"_id":3188,"_source":1456,"_file":3189,"_stem":3190,"_extension":1459},"/posts/circuit-breaking-resilience","Circuit Breaking in Distributed Systems","An expert guide to understanding and implementing circuit breakers in distributed systems, with practical Java examples using Resilience4j and best practices.","2024-07-15T11:00:00.000Z","Enhancing Resilience with Circuit Breaker Patterns","/assets/img/uploads/circuit-breaking-resilience.png",[14,1469,2379,2380,2381],"resilience","circuit-breaker","distributed-systems",{"type":23,"children":2383,"toc":3176},[2384,2392,2398,2403,2437,2442,2448,2453,2471,2477,2484,2489,2599,2605,2809,2815,2820,2987,2993,2998,3092,3097,3103,3126,3130,3135,3139,3172],{"type":26,"tag":27,"props":2385,"children":2386},{},[2387],{"type":26,"tag":31,"props":2388,"children":2389},{},[2390],{"type":35,"value":2391},"In modern distributed systems, failures are inevitable. The circuit breaker pattern helps maintain system stability by preventing failures from cascading across service boundaries. In this post, we'll dive deep into circuit breakers, explore their importance, and demonstrate practical implementation using Resilience4j in Java.",{"type":26,"tag":38,"props":2393,"children":2395},{"id":2394},"understanding-the-circuit-breaker-pattern",[2396],{"type":35,"value":2397},"Understanding the Circuit Breaker Pattern",{"type":26,"tag":31,"props":2399,"children":2400},{},[2401],{"type":35,"value":2402},"The circuit breaker pattern prevents a service from making repeated calls to an external service that is experiencing issues. It has three main states:",{"type":26,"tag":45,"props":2404,"children":2405},{},[2406,2417,2427],{"type":26,"tag":49,"props":2407,"children":2408},{},[2409,2415],{"type":26,"tag":2410,"props":2411,"children":2412},"strong",{},[2413],{"type":35,"value":2414},"Closed:",{"type":35,"value":2416}," All requests pass through normally.",{"type":26,"tag":49,"props":2418,"children":2419},{},[2420,2425],{"type":26,"tag":2410,"props":2421,"children":2422},{},[2423],{"type":35,"value":2424},"Open:",{"type":35,"value":2426}," Requests fail fast, bypassing the problematic service.",{"type":26,"tag":49,"props":2428,"children":2429},{},[2430,2435],{"type":26,"tag":2410,"props":2431,"children":2432},{},[2433],{"type":35,"value":2434},"Half-Open:",{"type":35,"value":2436}," A limited number of requests test if the external service has recovered.",{"type":26,"tag":31,"props":2438,"children":2439},{},[2440],{"type":35,"value":2441},"This mechanism helps improve the resilience and responsiveness of your systems.",{"type":26,"tag":38,"props":2443,"children":2445},{"id":2444},"when-to-use-circuit-breakers",[2446],{"type":35,"value":2447},"When to Use Circuit Breakers",{"type":26,"tag":31,"props":2449,"children":2450},{},[2451],{"type":35,"value":2452},"Circuit breakers are essential when:",{"type":26,"tag":45,"props":2454,"children":2455},{},[2456,2461,2466],{"type":26,"tag":49,"props":2457,"children":2458},{},[2459],{"type":35,"value":2460},"Your system relies on remote calls (microservices architecture, external APIs).",{"type":26,"tag":49,"props":2462,"children":2463},{},[2464],{"type":35,"value":2465},"You need to prevent failure propagation.",{"type":26,"tag":49,"props":2467,"children":2468},{},[2469],{"type":35,"value":2470},"You aim to improve user experience by quickly responding to failures.",{"type":26,"tag":38,"props":2472,"children":2474},{"id":2473},"implementing-circuit-breakers-with-resilience4j",[2475],{"type":35,"value":2476},"Implementing Circuit Breakers with Resilience4j",{"type":26,"tag":2478,"props":2479,"children":2481},"h3",{"id":2480},"step-1-adding-dependencies",[2482],{"type":35,"value":2483},"Step 1: Adding Dependencies",{"type":26,"tag":31,"props":2485,"children":2486},{},[2487],{"type":35,"value":2488},"Add Resilience4j dependencies to your project (Maven example):",{"type":26,"tag":76,"props":2490,"children":2492},{"className":2130,"code":2491,"language":2132,"meta":7,"style":7},"\u003Cdependency>\n    \u003CgroupId>io.github.resilience4j\u003C/groupId>\n    \u003CartifactId>resilience4j-circuitbreaker\u003C/artifactId>\n    \u003Cversion>2.0.2\u003C/version>\n\u003C/dependency>\n",[2493],{"type":26,"tag":14,"props":2494,"children":2495},{"__ignoreMap":7},[2496,2512,2536,2560,2584],{"type":26,"tag":86,"props":2497,"children":2498},{"class":88,"line":89},[2499,2503,2508],{"type":26,"tag":86,"props":2500,"children":2501},{"style":183},[2502],{"type":35,"value":2144},{"type":26,"tag":86,"props":2504,"children":2505},{"style":2147},[2506],{"type":35,"value":2507},"dependency",{"type":26,"tag":86,"props":2509,"children":2510},{"style":183},[2511],{"type":35,"value":2155},{"type":26,"tag":86,"props":2513,"children":2514},{"class":88,"line":199},[2515,2519,2523,2528,2532],{"type":26,"tag":86,"props":2516,"children":2517},{"style":183},[2518],{"type":35,"value":2163},{"type":26,"tag":86,"props":2520,"children":2521},{"style":2147},[2522],{"type":35,"value":2168},{"type":26,"tag":86,"props":2524,"children":2525},{"style":183},[2526],{"type":35,"value":2527},">io.github.resilience4j\u003C/",{"type":26,"tag":86,"props":2529,"children":2530},{"style":2147},[2531],{"type":35,"value":2168},{"type":26,"tag":86,"props":2533,"children":2534},{"style":183},[2535],{"type":35,"value":2155},{"type":26,"tag":86,"props":2537,"children":2538},{"class":88,"line":221},[2539,2543,2547,2552,2556],{"type":26,"tag":86,"props":2540,"children":2541},{"style":183},[2542],{"type":35,"value":2163},{"type":26,"tag":86,"props":2544,"children":2545},{"style":2147},[2546],{"type":35,"value":2193},{"type":26,"tag":86,"props":2548,"children":2549},{"style":183},[2550],{"type":35,"value":2551},">resilience4j-circuitbreaker\u003C/",{"type":26,"tag":86,"props":2553,"children":2554},{"style":2147},[2555],{"type":35,"value":2193},{"type":26,"tag":86,"props":2557,"children":2558},{"style":183},[2559],{"type":35,"value":2155},{"type":26,"tag":86,"props":2561,"children":2562},{"class":88,"line":234},[2563,2567,2571,2576,2580],{"type":26,"tag":86,"props":2564,"children":2565},{"style":183},[2566],{"type":35,"value":2163},{"type":26,"tag":86,"props":2568,"children":2569},{"style":2147},[2570],{"type":35,"value":2218},{"type":26,"tag":86,"props":2572,"children":2573},{"style":183},[2574],{"type":35,"value":2575},">2.0.2\u003C/",{"type":26,"tag":86,"props":2577,"children":2578},{"style":2147},[2579],{"type":35,"value":2218},{"type":26,"tag":86,"props":2581,"children":2582},{"style":183},[2583],{"type":35,"value":2155},{"type":26,"tag":86,"props":2585,"children":2586},{"class":88,"line":256},[2587,2591,2595],{"type":26,"tag":86,"props":2588,"children":2589},{"style":183},[2590],{"type":35,"value":2239},{"type":26,"tag":86,"props":2592,"children":2593},{"style":2147},[2594],{"type":35,"value":2507},{"type":26,"tag":86,"props":2596,"children":2597},{"style":183},[2598],{"type":35,"value":2155},{"type":26,"tag":2478,"props":2600,"children":2602},{"id":2601},"step-2-configuring-circuit-breaker",[2603],{"type":35,"value":2604},"Step 2: Configuring Circuit Breaker",{"type":26,"tag":76,"props":2606,"children":2608},{"className":1566,"code":2607,"language":1469,"meta":7,"style":7},"CircuitBreakerConfig config = CircuitBreakerConfig.custom()\n    .failureRateThreshold(50)\n    .waitDurationInOpenState(Duration.ofMillis(1000))\n    .permittedNumberOfCallsInHalfOpenState(2)\n    .minimumNumberOfCalls(5)\n    .build();\n\nCircuitBreaker circuitBreaker = CircuitBreaker.of(\"myService\", config);\n",[2609],{"type":26,"tag":14,"props":2610,"children":2611},{"__ignoreMap":7},[2612,2639,2665,2701,2725,2750,2766,2773],{"type":26,"tag":86,"props":2613,"children":2614},{"class":88,"line":89},[2615,2620,2624,2629,2634],{"type":26,"tag":86,"props":2616,"children":2617},{"style":183},[2618],{"type":35,"value":2619},"CircuitBreakerConfig config ",{"type":26,"tag":86,"props":2621,"children":2622},{"style":177},[2623],{"type":35,"value":324},{"type":26,"tag":86,"props":2625,"children":2626},{"style":183},[2627],{"type":35,"value":2628}," CircuitBreakerConfig.",{"type":26,"tag":86,"props":2630,"children":2631},{"style":93},[2632],{"type":35,"value":2633},"custom",{"type":26,"tag":86,"props":2635,"children":2636},{"style":183},[2637],{"type":35,"value":2638},"()\n",{"type":26,"tag":86,"props":2640,"children":2641},{"class":88,"line":199},[2642,2647,2652,2656,2661],{"type":26,"tag":86,"props":2643,"children":2644},{"style":183},[2645],{"type":35,"value":2646},"    .",{"type":26,"tag":86,"props":2648,"children":2649},{"style":93},[2650],{"type":35,"value":2651},"failureRateThreshold",{"type":26,"tag":86,"props":2653,"children":2654},{"style":183},[2655],{"type":35,"value":1281},{"type":26,"tag":86,"props":2657,"children":2658},{"style":287},[2659],{"type":35,"value":2660},"50",{"type":26,"tag":86,"props":2662,"children":2663},{"style":183},[2664],{"type":35,"value":310},{"type":26,"tag":86,"props":2666,"children":2667},{"class":88,"line":221},[2668,2672,2677,2682,2687,2691,2696],{"type":26,"tag":86,"props":2669,"children":2670},{"style":183},[2671],{"type":35,"value":2646},{"type":26,"tag":86,"props":2673,"children":2674},{"style":93},[2675],{"type":35,"value":2676},"waitDurationInOpenState",{"type":26,"tag":86,"props":2678,"children":2679},{"style":183},[2680],{"type":35,"value":2681},"(Duration.",{"type":26,"tag":86,"props":2683,"children":2684},{"style":93},[2685],{"type":35,"value":2686},"ofMillis",{"type":26,"tag":86,"props":2688,"children":2689},{"style":183},[2690],{"type":35,"value":1281},{"type":26,"tag":86,"props":2692,"children":2693},{"style":287},[2694],{"type":35,"value":2695},"1000",{"type":26,"tag":86,"props":2697,"children":2698},{"style":183},[2699],{"type":35,"value":2700},"))\n",{"type":26,"tag":86,"props":2702,"children":2703},{"class":88,"line":234},[2704,2708,2713,2717,2721],{"type":26,"tag":86,"props":2705,"children":2706},{"style":183},[2707],{"type":35,"value":2646},{"type":26,"tag":86,"props":2709,"children":2710},{"style":93},[2711],{"type":35,"value":2712},"permittedNumberOfCallsInHalfOpenState",{"type":26,"tag":86,"props":2714,"children":2715},{"style":183},[2716],{"type":35,"value":1281},{"type":26,"tag":86,"props":2718,"children":2719},{"style":287},[2720],{"type":35,"value":1654},{"type":26,"tag":86,"props":2722,"children":2723},{"style":183},[2724],{"type":35,"value":310},{"type":26,"tag":86,"props":2726,"children":2727},{"class":88,"line":256},[2728,2732,2737,2741,2746],{"type":26,"tag":86,"props":2729,"children":2730},{"style":183},[2731],{"type":35,"value":2646},{"type":26,"tag":86,"props":2733,"children":2734},{"style":93},[2735],{"type":35,"value":2736},"minimumNumberOfCalls",{"type":26,"tag":86,"props":2738,"children":2739},{"style":183},[2740],{"type":35,"value":1281},{"type":26,"tag":86,"props":2742,"children":2743},{"style":287},[2744],{"type":35,"value":2745},"5",{"type":26,"tag":86,"props":2747,"children":2748},{"style":183},[2749],{"type":35,"value":310},{"type":26,"tag":86,"props":2751,"children":2752},{"class":88,"line":266},[2753,2757,2762],{"type":26,"tag":86,"props":2754,"children":2755},{"style":183},[2756],{"type":35,"value":2646},{"type":26,"tag":86,"props":2758,"children":2759},{"style":93},[2760],{"type":35,"value":2761},"build",{"type":26,"tag":86,"props":2763,"children":2764},{"style":183},[2765],{"type":35,"value":1686},{"type":26,"tag":86,"props":2767,"children":2768},{"class":88,"line":275},[2769],{"type":26,"tag":86,"props":2770,"children":2771},{"emptyLinePlaceholder":260},[2772],{"type":35,"value":263},{"type":26,"tag":86,"props":2774,"children":2775},{"class":88,"line":283},[2776,2781,2785,2790,2795,2799,2804],{"type":26,"tag":86,"props":2777,"children":2778},{"style":183},[2779],{"type":35,"value":2780},"CircuitBreaker circuitBreaker ",{"type":26,"tag":86,"props":2782,"children":2783},{"style":177},[2784],{"type":35,"value":324},{"type":26,"tag":86,"props":2786,"children":2787},{"style":183},[2788],{"type":35,"value":2789}," CircuitBreaker.",{"type":26,"tag":86,"props":2791,"children":2792},{"style":93},[2793],{"type":35,"value":2794},"of",{"type":26,"tag":86,"props":2796,"children":2797},{"style":183},[2798],{"type":35,"value":1281},{"type":26,"tag":86,"props":2800,"children":2801},{"style":99},[2802],{"type":35,"value":2803},"\"myService\"",{"type":26,"tag":86,"props":2805,"children":2806},{"style":183},[2807],{"type":35,"value":2808},", config);\n",{"type":26,"tag":2478,"props":2810,"children":2812},{"id":2811},"step-3-using-circuit-breaker",[2813],{"type":35,"value":2814},"Step 3: Using Circuit Breaker",{"type":26,"tag":31,"props":2816,"children":2817},{},[2818],{"type":35,"value":2819},"Wrap service calls using the circuit breaker:",{"type":26,"tag":76,"props":2821,"children":2823},{"className":1566,"code":2822,"language":1469,"meta":7,"style":7},"Supplier\u003CString> decoratedSupplier = CircuitBreaker.decorateSupplier(circuitBreaker, () -> myService.remoteCall());\n\nTry.ofSupplier(decoratedSupplier)\n    .recover(throwable -> \"Fallback response\")\n    .onSuccess(result -> System.out.println(\"Response: \" + result));\n",[2824],{"type":26,"tag":14,"props":2825,"children":2826},{"__ignoreMap":7},[2827,2882,2889,2907,2937],{"type":26,"tag":86,"props":2828,"children":2829},{"class":88,"line":89},[2830,2835,2840,2845,2849,2853,2858,2863,2868,2873,2878],{"type":26,"tag":86,"props":2831,"children":2832},{"style":183},[2833],{"type":35,"value":2834},"Supplier\u003C",{"type":26,"tag":86,"props":2836,"children":2837},{"style":177},[2838],{"type":35,"value":2839},"String",{"type":26,"tag":86,"props":2841,"children":2842},{"style":183},[2843],{"type":35,"value":2844},"> decoratedSupplier ",{"type":26,"tag":86,"props":2846,"children":2847},{"style":177},[2848],{"type":35,"value":324},{"type":26,"tag":86,"props":2850,"children":2851},{"style":183},[2852],{"type":35,"value":2789},{"type":26,"tag":86,"props":2854,"children":2855},{"style":93},[2856],{"type":35,"value":2857},"decorateSupplier",{"type":26,"tag":86,"props":2859,"children":2860},{"style":183},[2861],{"type":35,"value":2862},"(circuitBreaker, () ",{"type":26,"tag":86,"props":2864,"children":2865},{"style":177},[2866],{"type":35,"value":2867},"->",{"type":26,"tag":86,"props":2869,"children":2870},{"style":183},[2871],{"type":35,"value":2872}," myService.",{"type":26,"tag":86,"props":2874,"children":2875},{"style":93},[2876],{"type":35,"value":2877},"remoteCall",{"type":26,"tag":86,"props":2879,"children":2880},{"style":183},[2881],{"type":35,"value":1765},{"type":26,"tag":86,"props":2883,"children":2884},{"class":88,"line":199},[2885],{"type":26,"tag":86,"props":2886,"children":2887},{"emptyLinePlaceholder":260},[2888],{"type":35,"value":263},{"type":26,"tag":86,"props":2890,"children":2891},{"class":88,"line":221},[2892,2897,2902],{"type":26,"tag":86,"props":2893,"children":2894},{"style":183},[2895],{"type":35,"value":2896},"Try.",{"type":26,"tag":86,"props":2898,"children":2899},{"style":93},[2900],{"type":35,"value":2901},"ofSupplier",{"type":26,"tag":86,"props":2903,"children":2904},{"style":183},[2905],{"type":35,"value":2906},"(decoratedSupplier)\n",{"type":26,"tag":86,"props":2908,"children":2909},{"class":88,"line":234},[2910,2914,2919,2924,2928,2933],{"type":26,"tag":86,"props":2911,"children":2912},{"style":183},[2913],{"type":35,"value":2646},{"type":26,"tag":86,"props":2915,"children":2916},{"style":93},[2917],{"type":35,"value":2918},"recover",{"type":26,"tag":86,"props":2920,"children":2921},{"style":183},[2922],{"type":35,"value":2923},"(throwable ",{"type":26,"tag":86,"props":2925,"children":2926},{"style":177},[2927],{"type":35,"value":2867},{"type":26,"tag":86,"props":2929,"children":2930},{"style":99},[2931],{"type":35,"value":2932}," \"Fallback response\"",{"type":26,"tag":86,"props":2934,"children":2935},{"style":183},[2936],{"type":35,"value":310},{"type":26,"tag":86,"props":2938,"children":2939},{"class":88,"line":256},[2940,2944,2949,2954,2958,2963,2968,2972,2977,2982],{"type":26,"tag":86,"props":2941,"children":2942},{"style":183},[2943],{"type":35,"value":2646},{"type":26,"tag":86,"props":2945,"children":2946},{"style":93},[2947],{"type":35,"value":2948},"onSuccess",{"type":26,"tag":86,"props":2950,"children":2951},{"style":183},[2952],{"type":35,"value":2953},"(result ",{"type":26,"tag":86,"props":2955,"children":2956},{"style":177},[2957],{"type":35,"value":2867},{"type":26,"tag":86,"props":2959,"children":2960},{"style":183},[2961],{"type":35,"value":2962}," System.out.",{"type":26,"tag":86,"props":2964,"children":2965},{"style":93},[2966],{"type":35,"value":2967},"println",{"type":26,"tag":86,"props":2969,"children":2970},{"style":183},[2971],{"type":35,"value":1281},{"type":26,"tag":86,"props":2973,"children":2974},{"style":99},[2975],{"type":35,"value":2976},"\"Response: \"",{"type":26,"tag":86,"props":2978,"children":2979},{"style":177},[2980],{"type":35,"value":2981}," +",{"type":26,"tag":86,"props":2983,"children":2984},{"style":183},[2985],{"type":35,"value":2986}," result));\n",{"type":26,"tag":38,"props":2988,"children":2990},{"id":2989},"monitoring-and-metrics",[2991],{"type":35,"value":2992},"Monitoring and Metrics",{"type":26,"tag":31,"props":2994,"children":2995},{},[2996],{"type":35,"value":2997},"Resilience4j provides built-in support for metrics and monitoring:",{"type":26,"tag":76,"props":2999,"children":3001},{"className":1566,"code":3000,"language":1469,"meta":7,"style":7},"CircuitBreakerRegistry registry = CircuitBreakerRegistry.ofDefaults();\nregistry.getEventPublisher()\n    .onStateTransition(event -> System.out.println(event.getStateTransition()));\n",[3002],{"type":26,"tag":14,"props":3003,"children":3004},{"__ignoreMap":7},[3005,3031,3048],{"type":26,"tag":86,"props":3006,"children":3007},{"class":88,"line":89},[3008,3013,3017,3022,3027],{"type":26,"tag":86,"props":3009,"children":3010},{"style":183},[3011],{"type":35,"value":3012},"CircuitBreakerRegistry registry ",{"type":26,"tag":86,"props":3014,"children":3015},{"style":177},[3016],{"type":35,"value":324},{"type":26,"tag":86,"props":3018,"children":3019},{"style":183},[3020],{"type":35,"value":3021}," CircuitBreakerRegistry.",{"type":26,"tag":86,"props":3023,"children":3024},{"style":93},[3025],{"type":35,"value":3026},"ofDefaults",{"type":26,"tag":86,"props":3028,"children":3029},{"style":183},[3030],{"type":35,"value":1686},{"type":26,"tag":86,"props":3032,"children":3033},{"class":88,"line":199},[3034,3039,3044],{"type":26,"tag":86,"props":3035,"children":3036},{"style":183},[3037],{"type":35,"value":3038},"registry.",{"type":26,"tag":86,"props":3040,"children":3041},{"style":93},[3042],{"type":35,"value":3043},"getEventPublisher",{"type":26,"tag":86,"props":3045,"children":3046},{"style":183},[3047],{"type":35,"value":2638},{"type":26,"tag":86,"props":3049,"children":3050},{"class":88,"line":221},[3051,3055,3060,3065,3069,3073,3077,3082,3087],{"type":26,"tag":86,"props":3052,"children":3053},{"style":183},[3054],{"type":35,"value":2646},{"type":26,"tag":86,"props":3056,"children":3057},{"style":93},[3058],{"type":35,"value":3059},"onStateTransition",{"type":26,"tag":86,"props":3061,"children":3062},{"style":183},[3063],{"type":35,"value":3064},"(event ",{"type":26,"tag":86,"props":3066,"children":3067},{"style":177},[3068],{"type":35,"value":2867},{"type":26,"tag":86,"props":3070,"children":3071},{"style":183},[3072],{"type":35,"value":2962},{"type":26,"tag":86,"props":3074,"children":3075},{"style":93},[3076],{"type":35,"value":2967},{"type":26,"tag":86,"props":3078,"children":3079},{"style":183},[3080],{"type":35,"value":3081},"(event.",{"type":26,"tag":86,"props":3083,"children":3084},{"style":93},[3085],{"type":35,"value":3086},"getStateTransition",{"type":26,"tag":86,"props":3088,"children":3089},{"style":183},[3090],{"type":35,"value":3091},"()));\n",{"type":26,"tag":31,"props":3093,"children":3094},{},[3095],{"type":35,"value":3096},"Integrate with Prometheus, Grafana, or other observability tools for comprehensive monitoring.",{"type":26,"tag":38,"props":3098,"children":3100},{"id":3099},"best-practices-for-circuit-breaking",[3101],{"type":35,"value":3102},"Best Practices for Circuit Breaking",{"type":26,"tag":45,"props":3104,"children":3105},{},[3106,3111,3116,3121],{"type":26,"tag":49,"props":3107,"children":3108},{},[3109],{"type":35,"value":3110},"Configure sensible thresholds to avoid premature circuit opening.",{"type":26,"tag":49,"props":3112,"children":3113},{},[3114],{"type":35,"value":3115},"Always define fallback mechanisms.",{"type":26,"tag":49,"props":3117,"children":3118},{},[3119],{"type":35,"value":3120},"Regularly monitor circuit breaker states and metrics.",{"type":26,"tag":49,"props":3122,"children":3123},{},[3124],{"type":35,"value":3125},"Test thoroughly to ensure reliability under failure conditions.",{"type":26,"tag":38,"props":3127,"children":3128},{"id":2304},[3129],{"type":35,"value":2307},{"type":26,"tag":31,"props":3131,"children":3132},{},[3133],{"type":35,"value":3134},"Implementing circuit breakers using Resilience4j significantly enhances the resilience of your Java-based distributed systems. This proactive approach ensures your systems gracefully handle failures, maintaining service availability and user satisfaction.",{"type":26,"tag":1396,"props":3136,"children":3137},{"id":2315},[3138],{"type":35,"value":2318},{"type":26,"tag":45,"props":3140,"children":3141},{},[3142,3152,3162],{"type":26,"tag":49,"props":3143,"children":3144},{},[3145],{"type":26,"tag":1409,"props":3146,"children":3149},{"href":3147,"rel":3148},"https://resilience4j.readme.io/docs",[1413],[3150],{"type":35,"value":3151},"Resilience4j Official Documentation",{"type":26,"tag":49,"props":3153,"children":3154},{},[3155],{"type":26,"tag":1409,"props":3156,"children":3159},{"href":3157,"rel":3158},"https://martinfowler.com/bliki/CircuitBreaker.html",[1413],[3160],{"type":35,"value":3161},"Circuit Breaker Pattern by Martin Fowler",{"type":26,"tag":49,"props":3163,"children":3164},{},[3165],{"type":26,"tag":1409,"props":3166,"children":3169},{"href":3167,"rel":3168},"https://microservices.io/patterns/reliability/circuit-breaker.html",[1413],[3170],{"type":35,"value":3171},"Microservices Patterns by Chris Richardson",{"type":26,"tag":1438,"props":3173,"children":3174},{},[3175],{"type":35,"value":1442},{"title":7,"searchDepth":199,"depth":199,"links":3177},[3178,3179,3180,3185,3186,3187],{"id":2394,"depth":199,"text":2397},{"id":2444,"depth":199,"text":2447},{"id":2473,"depth":199,"text":2476,"children":3181},[3182,3183,3184],{"id":2480,"depth":221,"text":2483},{"id":2601,"depth":221,"text":2604},{"id":2811,"depth":221,"text":2814},{"id":2989,"depth":199,"text":2992},{"id":3099,"depth":199,"text":3102},{"id":2304,"depth":199,"text":2307},"content:posts:circuit-breaking-resilience.md","posts/circuit-breaking-resilience.md","posts/circuit-breaking-resilience",{"_path":3192,"_dir":5,"_draft":6,"_partial":6,"_locale":7,"title":3193,"description":3194,"date":3195,"layout":11,"subtitle":3196,"image":3197,"optimized_image":3197,"category":14,"tags":3198,"author":21,"paginate":6,"body":3202,"_type":1454,"_id":4198,"_source":1456,"_file":4199,"_stem":4200,"_extension":1459},"/posts/maven-and-github-actions","Automating Java Builds with Maven and GitHub Actions CI/CD","Learn how to set up automated Java build pipelines using Maven and GitHub Actions, including practical examples and detailed instructions.","2024-06-15T11:00:00.000Z","A Step-by-Step Guide to Continuous Integration and Deployment","/assets/img/uploads/java-maven-github-actions.png",[14,1469,3199,3200,3201],"maven","github-actions","cicd",{"type":23,"children":3203,"toc":4187},[3204,3226,3232,3253,3259,3264,3272,3285,3616,3622,3681,3687,3692,3852,3858,3863,3935,3947,3953,3958,4017,4029,4035,4058,4064,4069,4124,4137,4141,4146,4150,4183],{"type":26,"tag":27,"props":3205,"children":3206},{},[3207],{"type":26,"tag":31,"props":3208,"children":3209},{},[3210,3212,3217,3219,3224],{"type":35,"value":3211},"Continuous Integration and Continuous Deployment (CI/CD) streamline development workflows, improve software quality, and accelerate delivery. This tutorial guides you through setting up automated Java builds using ",{"type":26,"tag":2410,"props":3213,"children":3214},{},[3215],{"type":35,"value":3216},"Maven",{"type":35,"value":3218}," and ",{"type":26,"tag":2410,"props":3220,"children":3221},{},[3222],{"type":35,"value":3223},"GitHub Actions",{"type":35,"value":3225},".",{"type":26,"tag":38,"props":3227,"children":3229},{"id":3228},"prerequisites",[3230],{"type":35,"value":3231},"Prerequisites",{"type":26,"tag":45,"props":3233,"children":3234},{},[3235,3248],{"type":26,"tag":49,"props":3236,"children":3237},{},[3238,3240,3246],{"type":35,"value":3239},"A Java project with Maven configured (",{"type":26,"tag":14,"props":3241,"children":3243},{"className":3242},[],[3244],{"type":35,"value":3245},"pom.xml",{"type":35,"value":3247},").",{"type":26,"tag":49,"props":3249,"children":3250},{},[3251],{"type":35,"value":3252},"GitHub repository.",{"type":26,"tag":38,"props":3254,"children":3256},{"id":3255},"step-1-setting-up-your-github-actions-workflow",[3257],{"type":35,"value":3258},"Step 1: Setting Up Your GitHub Actions Workflow",{"type":26,"tag":31,"props":3260,"children":3261},{},[3262],{"type":35,"value":3263},"In your repository, create the following directory structure:",{"type":26,"tag":76,"props":3265,"children":3267},{"code":3266},".github/workflows/\n",[3268],{"type":26,"tag":14,"props":3269,"children":3270},{"__ignoreMap":7},[3271],{"type":35,"value":3266},{"type":26,"tag":31,"props":3273,"children":3274},{},[3275,3277,3283],{"type":35,"value":3276},"Create a new file named ",{"type":26,"tag":14,"props":3278,"children":3280},{"className":3279},[],[3281],{"type":35,"value":3282},"maven-ci.yml",{"type":35,"value":3284}," within this directory:",{"type":26,"tag":76,"props":3286,"children":3290},{"code":3287,"language":3288,"meta":7,"className":3289,"style":7},"name: Maven CI\n\non:\n  push:\n    branches: [ \"main\" ]\n  pull_request:\n    branches: [ \"main\" ]\n\njobs:\n  build:\n    runs-on: ubuntu-latest\n\n    steps:\n      - uses: actions/checkout@v4\n      - name: Set up JDK 21\n        uses: actions/setup-java@v4\n        with:\n          java-version: '21'\n          distribution: 'temurin'\n\n      - name: Build with Maven\n        run: mvn clean install\n","yml","language-yml shiki shiki-themes github-dark github-light",[3291],{"type":26,"tag":14,"props":3292,"children":3293},{"__ignoreMap":7},[3294,3311,3318,3330,3342,3365,3377,3396,3403,3415,3427,3444,3451,3463,3485,3505,3522,3534,3551,3569,3577,3598],{"type":26,"tag":86,"props":3295,"children":3296},{"class":88,"line":89},[3297,3302,3306],{"type":26,"tag":86,"props":3298,"children":3299},{"style":2147},[3300],{"type":35,"value":3301},"name",{"type":26,"tag":86,"props":3303,"children":3304},{"style":183},[3305],{"type":35,"value":906},{"type":26,"tag":86,"props":3307,"children":3308},{"style":99},[3309],{"type":35,"value":3310},"Maven CI\n",{"type":26,"tag":86,"props":3312,"children":3313},{"class":88,"line":199},[3314],{"type":26,"tag":86,"props":3315,"children":3316},{"emptyLinePlaceholder":260},[3317],{"type":35,"value":263},{"type":26,"tag":86,"props":3319,"children":3320},{"class":88,"line":221},[3321,3326],{"type":26,"tag":86,"props":3322,"children":3323},{"style":287},[3324],{"type":35,"value":3325},"on",{"type":26,"tag":86,"props":3327,"children":3328},{"style":183},[3329],{"type":35,"value":1215},{"type":26,"tag":86,"props":3331,"children":3332},{"class":88,"line":234},[3333,3338],{"type":26,"tag":86,"props":3334,"children":3335},{"style":2147},[3336],{"type":35,"value":3337},"  push",{"type":26,"tag":86,"props":3339,"children":3340},{"style":183},[3341],{"type":35,"value":1215},{"type":26,"tag":86,"props":3343,"children":3344},{"class":88,"line":256},[3345,3350,3355,3360],{"type":26,"tag":86,"props":3346,"children":3347},{"style":2147},[3348],{"type":35,"value":3349},"    branches",{"type":26,"tag":86,"props":3351,"children":3352},{"style":183},[3353],{"type":35,"value":3354},": [ ",{"type":26,"tag":86,"props":3356,"children":3357},{"style":99},[3358],{"type":35,"value":3359},"\"main\"",{"type":26,"tag":86,"props":3361,"children":3362},{"style":183},[3363],{"type":35,"value":3364}," ]\n",{"type":26,"tag":86,"props":3366,"children":3367},{"class":88,"line":266},[3368,3373],{"type":26,"tag":86,"props":3369,"children":3370},{"style":2147},[3371],{"type":35,"value":3372},"  pull_request",{"type":26,"tag":86,"props":3374,"children":3375},{"style":183},[3376],{"type":35,"value":1215},{"type":26,"tag":86,"props":3378,"children":3379},{"class":88,"line":275},[3380,3384,3388,3392],{"type":26,"tag":86,"props":3381,"children":3382},{"style":2147},[3383],{"type":35,"value":3349},{"type":26,"tag":86,"props":3385,"children":3386},{"style":183},[3387],{"type":35,"value":3354},{"type":26,"tag":86,"props":3389,"children":3390},{"style":99},[3391],{"type":35,"value":3359},{"type":26,"tag":86,"props":3393,"children":3394},{"style":183},[3395],{"type":35,"value":3364},{"type":26,"tag":86,"props":3397,"children":3398},{"class":88,"line":283},[3399],{"type":26,"tag":86,"props":3400,"children":3401},{"emptyLinePlaceholder":260},[3402],{"type":35,"value":263},{"type":26,"tag":86,"props":3404,"children":3405},{"class":88,"line":313},[3406,3411],{"type":26,"tag":86,"props":3407,"children":3408},{"style":2147},[3409],{"type":35,"value":3410},"jobs",{"type":26,"tag":86,"props":3412,"children":3413},{"style":183},[3414],{"type":35,"value":1215},{"type":26,"tag":86,"props":3416,"children":3417},{"class":88,"line":340},[3418,3423],{"type":26,"tag":86,"props":3419,"children":3420},{"style":2147},[3421],{"type":35,"value":3422},"  build",{"type":26,"tag":86,"props":3424,"children":3425},{"style":183},[3426],{"type":35,"value":1215},{"type":26,"tag":86,"props":3428,"children":3429},{"class":88,"line":373},[3430,3435,3439],{"type":26,"tag":86,"props":3431,"children":3432},{"style":2147},[3433],{"type":35,"value":3434},"    runs-on",{"type":26,"tag":86,"props":3436,"children":3437},{"style":183},[3438],{"type":35,"value":906},{"type":26,"tag":86,"props":3440,"children":3441},{"style":99},[3442],{"type":35,"value":3443},"ubuntu-latest\n",{"type":26,"tag":86,"props":3445,"children":3446},{"class":88,"line":698},[3447],{"type":26,"tag":86,"props":3448,"children":3449},{"emptyLinePlaceholder":260},[3450],{"type":35,"value":263},{"type":26,"tag":86,"props":3452,"children":3453},{"class":88,"line":706},[3454,3459],{"type":26,"tag":86,"props":3455,"children":3456},{"style":2147},[3457],{"type":35,"value":3458},"    steps",{"type":26,"tag":86,"props":3460,"children":3461},{"style":183},[3462],{"type":35,"value":1215},{"type":26,"tag":86,"props":3464,"children":3465},{"class":88,"line":724},[3466,3471,3476,3480],{"type":26,"tag":86,"props":3467,"children":3468},{"style":183},[3469],{"type":35,"value":3470},"      - ",{"type":26,"tag":86,"props":3472,"children":3473},{"style":2147},[3474],{"type":35,"value":3475},"uses",{"type":26,"tag":86,"props":3477,"children":3478},{"style":183},[3479],{"type":35,"value":906},{"type":26,"tag":86,"props":3481,"children":3482},{"style":99},[3483],{"type":35,"value":3484},"actions/checkout@v4\n",{"type":26,"tag":86,"props":3486,"children":3487},{"class":88,"line":1038},[3488,3492,3496,3500],{"type":26,"tag":86,"props":3489,"children":3490},{"style":183},[3491],{"type":35,"value":3470},{"type":26,"tag":86,"props":3493,"children":3494},{"style":2147},[3495],{"type":35,"value":3301},{"type":26,"tag":86,"props":3497,"children":3498},{"style":183},[3499],{"type":35,"value":906},{"type":26,"tag":86,"props":3501,"children":3502},{"style":99},[3503],{"type":35,"value":3504},"Set up JDK 21\n",{"type":26,"tag":86,"props":3506,"children":3507},{"class":88,"line":1051},[3508,3513,3517],{"type":26,"tag":86,"props":3509,"children":3510},{"style":2147},[3511],{"type":35,"value":3512},"        uses",{"type":26,"tag":86,"props":3514,"children":3515},{"style":183},[3516],{"type":35,"value":906},{"type":26,"tag":86,"props":3518,"children":3519},{"style":99},[3520],{"type":35,"value":3521},"actions/setup-java@v4\n",{"type":26,"tag":86,"props":3523,"children":3524},{"class":88,"line":1059},[3525,3530],{"type":26,"tag":86,"props":3526,"children":3527},{"style":2147},[3528],{"type":35,"value":3529},"        with",{"type":26,"tag":86,"props":3531,"children":3532},{"style":183},[3533],{"type":35,"value":1215},{"type":26,"tag":86,"props":3535,"children":3536},{"class":88,"line":1087},[3537,3542,3546],{"type":26,"tag":86,"props":3538,"children":3539},{"style":2147},[3540],{"type":35,"value":3541},"          java-version",{"type":26,"tag":86,"props":3543,"children":3544},{"style":183},[3545],{"type":35,"value":906},{"type":26,"tag":86,"props":3547,"children":3548},{"style":99},[3549],{"type":35,"value":3550},"'21'\n",{"type":26,"tag":86,"props":3552,"children":3554},{"class":88,"line":3553},19,[3555,3560,3564],{"type":26,"tag":86,"props":3556,"children":3557},{"style":2147},[3558],{"type":35,"value":3559},"          distribution",{"type":26,"tag":86,"props":3561,"children":3562},{"style":183},[3563],{"type":35,"value":906},{"type":26,"tag":86,"props":3565,"children":3566},{"style":99},[3567],{"type":35,"value":3568},"'temurin'\n",{"type":26,"tag":86,"props":3570,"children":3572},{"class":88,"line":3571},20,[3573],{"type":26,"tag":86,"props":3574,"children":3575},{"emptyLinePlaceholder":260},[3576],{"type":35,"value":263},{"type":26,"tag":86,"props":3578,"children":3580},{"class":88,"line":3579},21,[3581,3585,3589,3593],{"type":26,"tag":86,"props":3582,"children":3583},{"style":183},[3584],{"type":35,"value":3470},{"type":26,"tag":86,"props":3586,"children":3587},{"style":2147},[3588],{"type":35,"value":3301},{"type":26,"tag":86,"props":3590,"children":3591},{"style":183},[3592],{"type":35,"value":906},{"type":26,"tag":86,"props":3594,"children":3595},{"style":99},[3596],{"type":35,"value":3597},"Build with Maven\n",{"type":26,"tag":86,"props":3599,"children":3601},{"class":88,"line":3600},22,[3602,3607,3611],{"type":26,"tag":86,"props":3603,"children":3604},{"style":2147},[3605],{"type":35,"value":3606},"        run",{"type":26,"tag":86,"props":3608,"children":3609},{"style":183},[3610],{"type":35,"value":906},{"type":26,"tag":86,"props":3612,"children":3613},{"style":99},[3614],{"type":35,"value":3615},"mvn clean install\n",{"type":26,"tag":38,"props":3617,"children":3619},{"id":3618},"step-2-understanding-the-workflow",[3620],{"type":35,"value":3621},"Step 2: Understanding the Workflow",{"type":26,"tag":45,"props":3623,"children":3624},{},[3625,3643,3653,3663],{"type":26,"tag":49,"props":3626,"children":3627},{},[3628,3633,3635,3641],{"type":26,"tag":2410,"props":3629,"children":3630},{},[3631],{"type":35,"value":3632},"Trigger:",{"type":35,"value":3634}," Activated on push or pull request to the ",{"type":26,"tag":14,"props":3636,"children":3638},{"className":3637},[],[3639],{"type":35,"value":3640},"main",{"type":35,"value":3642}," branch.",{"type":26,"tag":49,"props":3644,"children":3645},{},[3646,3651],{"type":26,"tag":2410,"props":3647,"children":3648},{},[3649],{"type":35,"value":3650},"Checkout:",{"type":35,"value":3652}," Retrieves the source code from your repository.",{"type":26,"tag":49,"props":3654,"children":3655},{},[3656,3661],{"type":26,"tag":2410,"props":3657,"children":3658},{},[3659],{"type":35,"value":3660},"JDK Setup:",{"type":35,"value":3662}," Installs Java 21 from Temurin.",{"type":26,"tag":49,"props":3664,"children":3665},{},[3666,3671,3673,3679],{"type":26,"tag":2410,"props":3667,"children":3668},{},[3669],{"type":35,"value":3670},"Maven Build:",{"type":35,"value":3672}," Executes Maven goals (",{"type":26,"tag":14,"props":3674,"children":3676},{"className":3675},[],[3677],{"type":35,"value":3678},"clean install",{"type":35,"value":3680},") to compile, test, and package your Java application.",{"type":26,"tag":38,"props":3682,"children":3684},{"id":3683},"step-3-add-maven-test-reports",[3685],{"type":35,"value":3686},"Step 3: Add Maven Test Reports",{"type":26,"tag":31,"props":3688,"children":3689},{},[3690],{"type":35,"value":3691},"Enhance your workflow by generating and uploading test reports:",{"type":26,"tag":76,"props":3693,"children":3695},{"code":3694,"language":3288,"meta":7,"className":3289,"style":7},"- name: Run tests and upload reports\n  run: |\n    mvn test\n  continue-on-error: true\n\n- name: Upload test report\n  uses: actions/upload-artifact@v4\n  with:\n    name: test-report\n    path: target/surefire-reports/\n",[3696],{"type":26,"tag":14,"props":3697,"children":3698},{"__ignoreMap":7},[3699,3720,3737,3745,3762,3769,3789,3806,3818,3835],{"type":26,"tag":86,"props":3700,"children":3701},{"class":88,"line":89},[3702,3707,3711,3715],{"type":26,"tag":86,"props":3703,"children":3704},{"style":183},[3705],{"type":35,"value":3706},"- ",{"type":26,"tag":86,"props":3708,"children":3709},{"style":2147},[3710],{"type":35,"value":3301},{"type":26,"tag":86,"props":3712,"children":3713},{"style":183},[3714],{"type":35,"value":906},{"type":26,"tag":86,"props":3716,"children":3717},{"style":99},[3718],{"type":35,"value":3719},"Run tests and upload reports\n",{"type":26,"tag":86,"props":3721,"children":3722},{"class":88,"line":199},[3723,3728,3732],{"type":26,"tag":86,"props":3724,"children":3725},{"style":2147},[3726],{"type":35,"value":3727},"  run",{"type":26,"tag":86,"props":3729,"children":3730},{"style":183},[3731],{"type":35,"value":906},{"type":26,"tag":86,"props":3733,"children":3734},{"style":177},[3735],{"type":35,"value":3736},"|\n",{"type":26,"tag":86,"props":3738,"children":3739},{"class":88,"line":221},[3740],{"type":26,"tag":86,"props":3741,"children":3742},{"style":99},[3743],{"type":35,"value":3744},"    mvn test\n",{"type":26,"tag":86,"props":3746,"children":3747},{"class":88,"line":234},[3748,3753,3757],{"type":26,"tag":86,"props":3749,"children":3750},{"style":2147},[3751],{"type":35,"value":3752},"  continue-on-error",{"type":26,"tag":86,"props":3754,"children":3755},{"style":183},[3756],{"type":35,"value":906},{"type":26,"tag":86,"props":3758,"children":3759},{"style":287},[3760],{"type":35,"value":3761},"true\n",{"type":26,"tag":86,"props":3763,"children":3764},{"class":88,"line":256},[3765],{"type":26,"tag":86,"props":3766,"children":3767},{"emptyLinePlaceholder":260},[3768],{"type":35,"value":263},{"type":26,"tag":86,"props":3770,"children":3771},{"class":88,"line":266},[3772,3776,3780,3784],{"type":26,"tag":86,"props":3773,"children":3774},{"style":183},[3775],{"type":35,"value":3706},{"type":26,"tag":86,"props":3777,"children":3778},{"style":2147},[3779],{"type":35,"value":3301},{"type":26,"tag":86,"props":3781,"children":3782},{"style":183},[3783],{"type":35,"value":906},{"type":26,"tag":86,"props":3785,"children":3786},{"style":99},[3787],{"type":35,"value":3788},"Upload test report\n",{"type":26,"tag":86,"props":3790,"children":3791},{"class":88,"line":275},[3792,3797,3801],{"type":26,"tag":86,"props":3793,"children":3794},{"style":2147},[3795],{"type":35,"value":3796},"  uses",{"type":26,"tag":86,"props":3798,"children":3799},{"style":183},[3800],{"type":35,"value":906},{"type":26,"tag":86,"props":3802,"children":3803},{"style":99},[3804],{"type":35,"value":3805},"actions/upload-artifact@v4\n",{"type":26,"tag":86,"props":3807,"children":3808},{"class":88,"line":283},[3809,3814],{"type":26,"tag":86,"props":3810,"children":3811},{"style":2147},[3812],{"type":35,"value":3813},"  with",{"type":26,"tag":86,"props":3815,"children":3816},{"style":183},[3817],{"type":35,"value":1215},{"type":26,"tag":86,"props":3819,"children":3820},{"class":88,"line":313},[3821,3826,3830],{"type":26,"tag":86,"props":3822,"children":3823},{"style":2147},[3824],{"type":35,"value":3825},"    name",{"type":26,"tag":86,"props":3827,"children":3828},{"style":183},[3829],{"type":35,"value":906},{"type":26,"tag":86,"props":3831,"children":3832},{"style":99},[3833],{"type":35,"value":3834},"test-report\n",{"type":26,"tag":86,"props":3836,"children":3837},{"class":88,"line":340},[3838,3843,3847],{"type":26,"tag":86,"props":3839,"children":3840},{"style":2147},[3841],{"type":35,"value":3842},"    path",{"type":26,"tag":86,"props":3844,"children":3845},{"style":183},[3846],{"type":35,"value":906},{"type":26,"tag":86,"props":3848,"children":3849},{"style":99},[3850],{"type":35,"value":3851},"target/surefire-reports/\n",{"type":26,"tag":38,"props":3853,"children":3855},{"id":3854},"step-4-deploy-artifacts-optional",[3856],{"type":35,"value":3857},"Step 4: Deploy Artifacts (Optional)",{"type":26,"tag":31,"props":3859,"children":3860},{},[3861],{"type":35,"value":3862},"To automatically deploy artifacts, include the deployment steps:",{"type":26,"tag":76,"props":3864,"children":3866},{"code":3865,"language":3288,"meta":7,"className":3289,"style":7},"- name: Deploy package\n  env:\n    GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}\n  run: mvn deploy\n",[3867],{"type":26,"tag":14,"props":3868,"children":3869},{"__ignoreMap":7},[3870,3890,3902,3919],{"type":26,"tag":86,"props":3871,"children":3872},{"class":88,"line":89},[3873,3877,3881,3885],{"type":26,"tag":86,"props":3874,"children":3875},{"style":183},[3876],{"type":35,"value":3706},{"type":26,"tag":86,"props":3878,"children":3879},{"style":2147},[3880],{"type":35,"value":3301},{"type":26,"tag":86,"props":3882,"children":3883},{"style":183},[3884],{"type":35,"value":906},{"type":26,"tag":86,"props":3886,"children":3887},{"style":99},[3888],{"type":35,"value":3889},"Deploy package\n",{"type":26,"tag":86,"props":3891,"children":3892},{"class":88,"line":199},[3893,3898],{"type":26,"tag":86,"props":3894,"children":3895},{"style":2147},[3896],{"type":35,"value":3897},"  env",{"type":26,"tag":86,"props":3899,"children":3900},{"style":183},[3901],{"type":35,"value":1215},{"type":26,"tag":86,"props":3903,"children":3904},{"class":88,"line":221},[3905,3910,3914],{"type":26,"tag":86,"props":3906,"children":3907},{"style":2147},[3908],{"type":35,"value":3909},"    GITHUB_TOKEN",{"type":26,"tag":86,"props":3911,"children":3912},{"style":183},[3913],{"type":35,"value":906},{"type":26,"tag":86,"props":3915,"children":3916},{"style":99},[3917],{"type":35,"value":3918},"${{ secrets.GITHUB_TOKEN }}\n",{"type":26,"tag":86,"props":3920,"children":3921},{"class":88,"line":234},[3922,3926,3930],{"type":26,"tag":86,"props":3923,"children":3924},{"style":2147},[3925],{"type":35,"value":3727},{"type":26,"tag":86,"props":3927,"children":3928},{"style":183},[3929],{"type":35,"value":906},{"type":26,"tag":86,"props":3931,"children":3932},{"style":99},[3933],{"type":35,"value":3934},"mvn deploy\n",{"type":26,"tag":31,"props":3936,"children":3937},{},[3938,3940,3945],{"type":35,"value":3939},"Ensure your ",{"type":26,"tag":14,"props":3941,"children":3943},{"className":3942},[],[3944],{"type":35,"value":3245},{"type":35,"value":3946}," is configured for deployment (e.g., GitHub Packages).",{"type":26,"tag":38,"props":3948,"children":3950},{"id":3949},"step-5-committing-and-running-your-workflow",[3951],{"type":35,"value":3952},"Step 5: Committing and Running Your Workflow",{"type":26,"tag":31,"props":3954,"children":3955},{},[3956],{"type":35,"value":3957},"Commit your workflow file and push the changes:",{"type":26,"tag":76,"props":3959,"children":3961},{"code":3960,"language":80,"meta":7,"className":78,"style":7},"git add .github/workflows/maven-ci.yml\ngit commit -m \"Add Maven CI GitHub Actions workflow\"\ngit push\n",[3962],{"type":26,"tag":14,"props":3963,"children":3964},{"__ignoreMap":7},[3965,3983,4005],{"type":26,"tag":86,"props":3966,"children":3967},{"class":88,"line":89},[3968,3973,3978],{"type":26,"tag":86,"props":3969,"children":3970},{"style":93},[3971],{"type":35,"value":3972},"git",{"type":26,"tag":86,"props":3974,"children":3975},{"style":99},[3976],{"type":35,"value":3977}," add",{"type":26,"tag":86,"props":3979,"children":3980},{"style":99},[3981],{"type":35,"value":3982}," .github/workflows/maven-ci.yml\n",{"type":26,"tag":86,"props":3984,"children":3985},{"class":88,"line":199},[3986,3990,3995,4000],{"type":26,"tag":86,"props":3987,"children":3988},{"style":93},[3989],{"type":35,"value":3972},{"type":26,"tag":86,"props":3991,"children":3992},{"style":99},[3993],{"type":35,"value":3994}," commit",{"type":26,"tag":86,"props":3996,"children":3997},{"style":287},[3998],{"type":35,"value":3999}," -m",{"type":26,"tag":86,"props":4001,"children":4002},{"style":99},[4003],{"type":35,"value":4004}," \"Add Maven CI GitHub Actions workflow\"\n",{"type":26,"tag":86,"props":4006,"children":4007},{"class":88,"line":221},[4008,4012],{"type":26,"tag":86,"props":4009,"children":4010},{"style":93},[4011],{"type":35,"value":3972},{"type":26,"tag":86,"props":4013,"children":4014},{"style":99},[4015],{"type":35,"value":4016}," push\n",{"type":26,"tag":31,"props":4018,"children":4019},{},[4020,4022,4027],{"type":35,"value":4021},"Navigate to the ",{"type":26,"tag":2410,"props":4023,"children":4024},{},[4025],{"type":35,"value":4026},"Actions",{"type":35,"value":4028}," tab on your GitHub repository to view and monitor your pipeline.",{"type":26,"tag":38,"props":4030,"children":4032},{"id":4031},"advantages-of-automating-java-builds",[4033],{"type":35,"value":4034},"Advantages of Automating Java Builds",{"type":26,"tag":45,"props":4036,"children":4037},{},[4038,4043,4048,4053],{"type":26,"tag":49,"props":4039,"children":4040},{},[4041],{"type":35,"value":4042},"Rapid feedback on code integration.",{"type":26,"tag":49,"props":4044,"children":4045},{},[4046],{"type":35,"value":4047},"Early identification of bugs and issues.",{"type":26,"tag":49,"props":4049,"children":4050},{},[4051],{"type":35,"value":4052},"Automated testing and deployment.",{"type":26,"tag":49,"props":4054,"children":4055},{},[4056],{"type":35,"value":4057},"Improved reliability and consistency.",{"type":26,"tag":38,"props":4059,"children":4061},{"id":4060},"pricing",[4062],{"type":35,"value":4063},"Pricing",{"type":26,"tag":31,"props":4065,"children":4066},{},[4067],{"type":35,"value":4068},"GitHub Actions offers a generous free tier suitable for most projects:",{"type":26,"tag":45,"props":4070,"children":4071},{},[4072,4098],{"type":26,"tag":49,"props":4073,"children":4074},{},[4075,4080],{"type":26,"tag":2410,"props":4076,"children":4077},{},[4078],{"type":35,"value":4079},"Free Tier:",{"type":26,"tag":45,"props":4081,"children":4082},{},[4083,4088,4093],{"type":26,"tag":49,"props":4084,"children":4085},{},[4086],{"type":35,"value":4087},"2,000 minutes per month (private repositories).",{"type":26,"tag":49,"props":4089,"children":4090},{},[4091],{"type":35,"value":4092},"Unlimited minutes for public repositories.",{"type":26,"tag":49,"props":4094,"children":4095},{},[4096],{"type":35,"value":4097},"Free usage of GitHub-hosted runners for most common tasks.",{"type":26,"tag":49,"props":4099,"children":4100},{},[4101,4106],{"type":26,"tag":2410,"props":4102,"children":4103},{},[4104],{"type":35,"value":4105},"Additional Minutes:",{"type":26,"tag":45,"props":4107,"children":4108},{},[4109,4114,4119],{"type":26,"tag":49,"props":4110,"children":4111},{},[4112],{"type":35,"value":4113},"$0.008 per minute for Linux runners.",{"type":26,"tag":49,"props":4115,"children":4116},{},[4117],{"type":35,"value":4118},"$0.016 per minute for Windows runners.",{"type":26,"tag":49,"props":4120,"children":4121},{},[4122],{"type":35,"value":4123},"$0.08 per minute for macOS runners.",{"type":26,"tag":31,"props":4125,"children":4126},{},[4127,4129,4136],{"type":35,"value":4128},"For detailed and up-to-date pricing, visit ",{"type":26,"tag":1409,"props":4130,"children":4133},{"href":4131,"rel":4132},"https://github.com/pricing#actions",[1413],[4134],{"type":35,"value":4135},"GitHub Actions Pricing",{"type":35,"value":3225},{"type":26,"tag":38,"props":4138,"children":4139},{"id":2304},[4140],{"type":35,"value":2307},{"type":26,"tag":31,"props":4142,"children":4143},{},[4144],{"type":35,"value":4145},"Using GitHub Actions with Maven provides an efficient and robust CI/CD pipeline, significantly improving your development lifecycle. Start implementing these practices today and streamline your Java application delivery.",{"type":26,"tag":1396,"props":4147,"children":4148},{"id":2315},[4149],{"type":35,"value":2318},{"type":26,"tag":45,"props":4151,"children":4152},{},[4153,4163,4173],{"type":26,"tag":49,"props":4154,"children":4155},{},[4156],{"type":26,"tag":1409,"props":4157,"children":4160},{"href":4158,"rel":4159},"https://docs.github.com/en/actions",[1413],[4161],{"type":35,"value":4162},"GitHub Actions Documentation",{"type":26,"tag":49,"props":4164,"children":4165},{},[4166],{"type":26,"tag":1409,"props":4167,"children":4170},{"href":4168,"rel":4169},"https://maven.apache.org/guides/",[1413],[4171],{"type":35,"value":4172},"Maven Official Documentation",{"type":26,"tag":49,"props":4174,"children":4175},{},[4176],{"type":26,"tag":1409,"props":4177,"children":4180},{"href":4178,"rel":4179},"https://docs.github.com/en/packages/working-with-a-github-packages-registry",[1413],[4181],{"type":35,"value":4182},"Publishing Java Packages with GitHub Packages",{"type":26,"tag":1438,"props":4184,"children":4185},{},[4186],{"type":35,"value":1442},{"title":7,"searchDepth":199,"depth":199,"links":4188},[4189,4190,4191,4192,4193,4194,4195,4196,4197],{"id":3228,"depth":199,"text":3231},{"id":3255,"depth":199,"text":3258},{"id":3618,"depth":199,"text":3621},{"id":3683,"depth":199,"text":3686},{"id":3854,"depth":199,"text":3857},{"id":3949,"depth":199,"text":3952},{"id":4031,"depth":199,"text":4034},{"id":4060,"depth":199,"text":4063},{"id":2304,"depth":199,"text":2307},"content:posts:maven-and-github-actions.md","posts/maven-and-github-actions.md","posts/maven-and-github-actions",[4202,4203,4204,4205,4206,4210,4214,4218,4222,4226,4230,4234,4238,4242,4246,4250,4254,4258,4261,4265,4269],{"_path":4,"title":8,"date":10},{"_path":1462,"title":1463,"date":1465},{"_path":2372,"title":2373,"date":2375},{"_path":3192,"title":3193,"date":3195},{"_path":4207,"title":4208,"date":4209},"/posts/pattern-matching-sealed-classes-java21","A Guide to Pattern Matching and Sealed Classes in Java 21","2024-05-15T11:00:00.000Z",{"_path":4211,"title":4212,"date":4213},"/posts/async-java-completable-vs-reactive","Asynchronous Programming in Java: CompletableFuture vs Reactive Streams","2024-04-15T11:00:00.000Z",{"_path":4215,"title":4216,"date":4217},"/posts/mastering-concurrency","Mastering Concurrency in Java: Threads, Executors, and Virtual Threads","2024-03-15T11:00:00.000Z",{"_path":4219,"title":4220,"date":4221},"/posts/microservices-mistakes","Common Mistakes When Developing Microservices","2024-02-15T11:00:00.000Z",{"_path":4223,"title":4224,"date":4225},"/posts/tdd-testing","Test-Driven Development (TDD) in Java with JUnit and Mockito","2024-01-15T11:00:00.000Z",{"_path":4227,"title":4228,"date":4229},"/posts/single-table-design","Single Table Design","2023-12-27T11:00:00.000Z",{"_path":4231,"title":4232,"date":4233},"/posts/java-17","Exploring Java 17's New Features","2023-10-08T11:00:00.000Z",{"_path":4235,"title":4236,"date":4237},"/posts/hexagonal-architecture","Introduction to Hexagonal Architecture","2023-10-02 18:00:00",{"_path":4239,"title":4240,"date":4241},"/posts/terraform","Unleashing the Power of Infrastructure as Code (IaC)","2023-09-24 18:00:00",{"_path":4243,"title":4244,"date":4245},"/posts/python-virtual-environments","Python Virtual Environments (venv)","2023-09-17 22:00:00",{"_path":4247,"title":4248,"date":4249},"/posts/api-first-principles","API First principles","2023-09-01 22:15:18",{"_path":4251,"title":4252,"date":4253},"/posts/how-to-configure-ssh-key-based-authentication","How To Configure SSH Key-Based Authentication","2021-02-21 03:46:12",{"_path":4255,"title":4256,"date":4257},"/posts/algorithms-binary-search-tree","Algorithms - Binary Search Tree in kotlin","2020-12-06T11:00:00.000Z",{"_path":4259,"title":4260,"date":4257},"/posts/how-to-create-a-twitter-bot","How to create a Twitter bot",{"_path":4262,"title":4263,"date":4264},"/posts/manage-aws-infrastructure-with-terraform","Bootstrap complete Java application infrastructure in AWS with Terraform","2020-12-02T11:00:00.000Z",{"_path":4266,"title":4267,"date":4268},"/posts/algorithms-working-with-trees","Algorithms - Binary tree traversals in kotlin","2020-11-24T11:00:00.000Z",{"_path":4270,"title":4271,"date":4272},"/posts/playing-with-ocr-libraries","Playing with OCR libraries","2020-11-22T11:00:00.000Z",1790510065718]