So I would have thought that this would be how you derive the work on a spring: basically the same way you do with gravity and other contexts, use $$W=\vec{F}\cdot \vec{x}.$$ If you displace a spring by $x$, then it exerts a force $-k x$, so $F=-kx$, since the displacement is $x$.
So $$W=-kx^2.\qquad \leftarrow\text{ (however, apparently wrong!)}$$
I've seen the correct derivation of work in a spring (with an extra half) and don't doubt that it's correct, but also don't see where my logic fails in this alternate derivation.
Best Answer
Since the force is a function of distance, you need to integrate:
$$F = kx\\ W = \int F\ dx\\ W = \int k\ x\ dx\\ W = \frac12kx^2$$
Add signs as needed...
Your work considered the force to be constant - and that's not how springs work.