The potential energy of a spring is the energy stored by a spring due to its compression.
According to Hooke's law, the restoring force produced in a spring is given by,
F=-KX
Where, k=Constant
x=Displacement produced
Now, the potential energy would be equal to the work done on the restoring system,
Therefore, P.E=W=F.dx
If the work done by a force does not depends upon the initial and final point but depends upon the path taken, it is called a non conservative force.
Spring force is non conservative force because work done depends upon the actual path.