What is the definition of magnetic moment in quantum mechanics? 
*

*The general formula for the magnetic  moment of a charge configuration is defined as $$\vec{\mu} = \frac{1}{2} \int \vec{r} \times \vec{J} \,d^3r$$


*For an electron it's said that the correct equation relating it's spin and magnetic moment is is
$$\vec{\mu} =g\frac{q}{2m}\vec{S}$$


*It's said that the above equation cannot be justified classically and is a quantum mechanical phenomenon.
What is the definition of magnetic moment used in the quantum mechanical equation $$\vec{\mu} =g\frac{q}{2m}\vec{S}$$
 A: The magnetic moment $\vec{\mu}$ of a charge configuration is defined by
the torque $\vec{\tau}$ it feels when being in an external magnetic field $\vec{B}$
$$\vec{\tau}=\vec{\mu}\times\vec{B}$$
or equivalently by its potential energy $U$ when being in this external field $\vec{B}$
(see Magnetic Moment - Effects of an external magnetic field)
$$U=-\vec{\mu}\cdot\vec{B}.$$
This definition is used both for classical and for quantum-mechanical systems.
The difference begins when you want to get a relation between magnetic moment
$\vec{\mu}$ and angular momentum.
For orbital momentum $\vec{L}$ you have (both classically and quantum-mechanically)
$$\vec{\mu} = g\frac{q}{2m}\vec{L}\quad\text{, with } g=1$$
which can be derived theoretically and confirmed experimentally (by measuring the torque
or energy).
But for spin angular momentum $\vec{S}$ of the electron experiments show
$$\vec{\mu} = g\frac{q}{2m}\vec{S}\quad\text{, with } g=2.0023$$
which is roughly double the size than for orbital momentum.
This cannot be understood by classical mechanics.
But from Pauli's equation (i.e. with non-relativistic quantum mechanics) or from Dirac's equation (i.e. with relativistic
quantum mechanics) you can derive this formula with $g=2$.
And with the full theory of quantum electrodynamics
you can even derive it with the exact value $g=2.0023$
(see $g$-factor).
