# Is there a conservative force acting on a spring that oscillates in SHM?

If I were to stretch a spring, then I am doing positive work in order to increase the potential energy stored in the spring. Since the equation for the potential energy in this case is given by $$U(x)=\frac{1}{2}kx^2$$ i.e, the potential energy depends only on the displacement from a reference point. Then would there be a conservative force doing negative work on the spring in order to increase the potential energy or not since $U \propto x^2$ rather than $x$?

The force pulling the spring back into equilibrium (due to the tension in the spring) is a conservative force - the very definition of a conservative force is that it's minus the gradient of some potential, i.e. $\overrightarrow{F}(x,y,z)=-\nabla U(x,y,z)$. In the case of a spring in the $xy$-plane being stretched along the $x$ axis, the equation reduces to $\overrightarrow{F}=-\frac{\text{d}U}{\text{d}x}\overrightarrow{e_x}$, which is indeed the case, since the right hand side is $-kx\overrightarrow{e_x}$ so that $\overrightarrow{F}=-kx\overrightarrow{e_x}$, Hooke's law.
Another way to define a conservative force is that $\oint \overrightarrow{F}\cdot\text{ d}\overrightarrow{s}$ must equal zero. In other words, the work of this force along a random closed path must equal zero. This certainly is the case, since along any path, the work done by the spring force is independent of the path in between the end points.