Militarism has long been seen as a cause for WWI, and with good reason; the development of large armies (understandably) led to tensions between the European powers.
So, where did it all begin? To put it simply, the arms race was kickstarted by Germany’s success in the Franco-Prussian War of 1870-71. The consequent unification of Germany resulted in a big increase in military spending in both Germany and France. This was because the Germans knew that the French would want to recover the lost provinces of Alsace and Lorraine, whilst the French feared another attack by Germany.
And so, the pace of military expansion in both countries accelerated in the years up to 1914 as both France and Germany had the wealth and industrial capacity to support it. Germany pursued this option particularly as it didn’t have a history of democracy before WWI, which made it feel threatened because of its position in central Europe.
The rest of Europe followed France and Germany’s lead because around this time, pretty much every European country was fearful of having to face an enemy by themselves. And so they each proceeded to seek alliances whilst also engaging in militarism.