Germany (and France) benefit from the EU because they dominate the EU politically and the rules governing finance, trade, and the Euro are rigged in their favor. On the whole, their monetary contribution to the EU is smaller than their net benefit from the arrangement. When Britain was in the EU, they found that the benefits of EU membership were less than what they had to pay.
Germany has long had a mercantile trade policy. They wanted to be able to prevent countries from competitively devaluing their currencies so as to make their goods cheaper in foreign markets....thus competing against German goods. One of the huge benefits Germany got was a lot of the rest of Europe - especially southern Europe - joined the Euro and was therefore locked in on the currency. No more competitive devaluations of the currency. Essentially, Germany was buying export markets.