First of all, you have to realize that you are considering a classical continuous system. Thus, the partition function is an integral instead of a sum. For a single particle, this is:
$$
Z = \frac{1}{h^3}\int e^{-\beta H(\mathbf{p},\mathbf{q})}\mathrm{d}^3p\mathrm{d}^3q \quad,
$$
where $H(\mathbf{p},\mathbf{q})$ is the Hamiltonian with $\mathbf{p}$ and $\mathbf{q}$ being the canonical momentum and position, respectively. The prefactor $1/h^3$ corresponds to the $g_i$ in your question. As a common convention, $h$ is chosen to be Planck's constant.
In the case of two particles connected by a spring, the Hamiltonian is:
$$
H(\mathbf{p}_1,\mathbf{p}_2,\mathbf{q}_1,\mathbf{q}_2) = \frac{\mathbf{p}_1^2}{2m_1} + \frac{\mathbf{p}_2^2}{2m_2} + \frac{K}{2}\left(\lvert\mathbf{q}_1 - \mathbf{q}_2\rvert - l \right)^2
$$
This Hamiltonian nicely separates, when we calculate the partition function:
$$
Z = \frac{1}{h^6}\int e^{-\beta\frac{\mathbf{p}_1^2}{2m_1}}\mathrm{d}^3p_1\int e^{-\beta\frac{\mathbf{p}_2^2}{2m_2}}\mathrm{d}^3p_2\iint e^{-\beta\frac{K}{2}(\lvert\mathbf{q}_1 -\mathbf{q}_2\rvert - l)^2}\mathrm{d}^3q_1\mathrm{d}^3q_2
$$
The first two terms correspond to the kinetic energy. They contribute a factor of $(2\pi m_ik_BT)^{3/2}$ each. Thus, the partition sum is
$$
Z = \frac{1}{h^6} \left(2\pi k_BT\sqrt{m_1m_2}\right)^3\iint e^{-\beta\frac{K}{2}(\lvert\mathbf{q}_1 - \mathbf{q}_2\rvert -l)^2}\mathrm{d}^3q_1\mathrm{d}^3q_2
$$
To calculate the contribution of the last term in the Hamiltonian, we can first use the translational invariance, considering position $\mathbf{q}_1$ and the relative position $\mathbf{r} = \mathbf{q}_1 - \mathbf{q}_2$. The energy term depends only on $\mathbf{r}$.
$$
\frac{K}{2}\left(\lvert\mathbf{q}_1-\mathbf{q}_2\rvert -l\right)^2 = \frac{K}{2}\left(\lvert\mathbf{r}\rvert - l\right)^2
$$
and the translational invariance of $\mathbf{q}_1$ adds factor $V$ which is the available volume:
$$
\iint e^{-\beta\frac{K}{2}(\lvert\mathbf{q}_1-\mathbf{q}_2\rvert - l)^2}\mathrm{d}^3q_1\mathrm{d}^3q_2 = \int\mathrm{d}^3q_1\int e^{-\beta\frac{K}{2}(\lvert\mathbf{r}\rvert -l)^2}\mathrm{d}^3r = V\int e^{-\beta\frac{K}{2}(\lvert\mathbf{r}\rvert -l)^2}\mathrm{d}^3r
$$
In the next step, we can use the rotational symmetry of the spring potential and convert to spherical coordinates:
$$
\int e^{-\beta\frac{K}{2}(\lvert\mathbf{r}\rvert -l)^2}\mathrm{d}^3\mathbf{r} = \int\limits_0^\infty\int\limits_0^\pi\int\limits_0^{2\pi} e^{-\beta\frac{K}{2}(r - l)^2} r^2\sin{\theta}\,\mathrm{d}r\mathrm{d}\phi\mathrm{d}\theta = 4\pi \int\limits_0^\infty r^2 e^{-\beta\frac{K}{2}(r - l)^2}\mathrm{d}r = 4\pi I
$$
where the integral $I$ can be solved with standard techniques (even though it takes some effort). Thus, the total partition function is
$$
Z = \frac{4\pi}{h^6} V \left(2\pi k_BT\sqrt{m_1m_2}\right)^3\cdot I
$$