It is difficult to determine for certain, but Stephen King likely had the idea before the Simpsons. In an interview to promote Under the Dome, King said that he had the idea, and he fleshed it out into a good novel only to be told by his daughter-in-law that "it sounds like the Simpsons movie". Again, it is impossible to tell whether King had the idea first or Matt Groening (creator of The Simpsons), but they both told the story... in very different ways.
According to Stephen King, he originally started a novel called "Under the Dome" in 1976 but stopped after 75 pages or so. That manuscript was subsequently lost. In 1982, he attempted to re-write the story with a different premise titled "The Cannibals", writing 450 pages before abandoning it. In 2007, King returned to his original title, completing "Under the Dome" in 2009. The original use of the title is referenced in a book first published in 1984 called "Stephen King: The Art of Darkness" by Douglas E. Winter. This would tend to prove that Stephen King's idea of a dome trapping a community pre-dates "The Simpsons Movie" by about 30 years.
There are also lots of similarities with the Gone series by Michael Grant, and the idea traces back at least to 1965 Clifford Simak sci-fi novel "All Flesh is Grass", in which a small out-of-way American town is suddenly surrounded by an invisible force-field dome.
There are also similarities to the James Follet trilogy of novels "Wicca", "Temple of the Winds", and "The Silent Vulcan" published in 2000 which tells the story of a group of people who are mysteriously held within a domed force field in East Sussex, England. The dome has clear boundaries in length and breadth. The people in the story are suddenly faced with returning to the days of candlelight and hunting and gathering their own food. It looks at the way the "players" interact within a group now they are all "equal" and a fight for survival has begun.
And, of course, mention must be given to John Wyndham's "The Midwich Cookoos" (filmed as "Village of the Damned") where a village is encompassed in a hemisphere that renders unconscious anyone who crosses the boundary, rather than a physical exclusion. This is the true origin of the idea.
There is also a great similarity to the Comic Book created by Luna Brothers called Girls. Same premise: a small town, suddenly surrounded by a dome is isolated from the rest of the world and tension increase inside, making people "show their true colors". Luna's books are more intense and less "good-ending" as the series, and also there is a "girl" sub-plot (therefore the name of the books), with a higher sexual role in the drama. It's nothing about the Simpson its very different.