Any resonator can be seen as a section of a transmission line. Along a transmission line, a wave travels , and certain features in and around the line affects the wave. One can put an obstacle on the line and reflect the wave backwards. With two such obstacles, the wave "resonates" or travels here and there between those obstacles. The best conditions for such resonance are the distance between the obstacles which is one-half of the wavelength, low loss of the line, etc.
Cavity and other resonators are used with electromagnetic waves as well as acoustic waves. In lasers, two obstacles can form a Fabry-Perot resonator.