Disclosed is a locking device, including a first locking part, having a casing and a blocking piece arranged on the casing, a second locking part, having a spring lock element which is formed spring-elastic at least in sections, and magnetic means, which act between the blocking piece of the first locking part and the second locking part and cause a magnetic force between the blocking piece of the first locking part and the second locking part. To close the locking device the first locking part can be attached onto the second locking part in a closing direction. To release the locking device the spring lock element can be slid in an opening direction directed essentially lateral to the closing direction relative to the blocking piece.