In this paper, an energy harvester consisting of a cantilever beam, magnets, and magnetic springs embedded on its structure is proposed to harvest electricity energy. In order to extract energy from the system permanently, an adaptive controller is proposed. With the help of the proposed controller, it is prevented from damping the oscillations of the beam or excessive increasing in the amplitude of these oscillations. Also, the use of the proposed controller provides the possibility that despite the presence of unknown external disturbances such as wind waves and sudden changes of sea waves, as well as the uncertainty of the parameters of the cantilever beam, a permanent energy is harvested from the proposed mechanism. The equations describing the electromechanical behavior of the proposed mechanism are derived from Lagrange equations. On the other hand, dynamic surface control technique is employed to design the adaptive and control laws. The stability of the closed-loop system is shown using Lyapunov stability theory, and the tracking error converges to a small neighborhood around the origin. Numerical simulation for cantilever beam is investigated to clarify the effectiveness of the proposed mechanism and controller.