The teenage gunman who shot nine people dead in Munich had been planning his attack for a year, according to German authorities.

A spokesman for the Bavaria state prosecutor's office also said the victims of the shooting were not classmates of 18-year-old student David Ali Sonboly.

Sonboly, who bought a Glock pistol illegally along with more than 300 bullets, killed himself after the attack, which took place at a McDonald's restaurant in a shopping mall.

Thirty-five people were also injured in the attack.

People mourn near the crime scene at OEZ shopping center the day after a shooting spree left nine victims dead in Munich, Germany (Getty Images)

The teenager is reported to have been obsessed with mass killings and it is believed he hacked a Facebook account in order to lure people to McDonald's with the promise of a free meal.

Robert Heimberger, head of Bavaria's criminal police, said Sonboly had visited the town of Winnenden last year to take photographs of the scene of a previous school shooting in 2009.

He added that it was likely the Glock pistol was bought on the "dark net" market.

Mr Heimberger also said the parents of the dead, seven of whom were teenagers, were unable to be interviewed as they remained in shock.

Munich police chief Hubertus Andrae ruled out an Islamist militant link to the attack.

"Based on the searches, there are no indications whatsoever that there is a connection to Islamic State" or to the issue of refugees, he told a news conference.

He said the gunman was brought up in Munich and had spent time in psychiatric care.

A police search of the attacker's room recovered a book on teenage shooting sprees.

"Documents on shooting sprees were found, so the perpetrator obviously researched this subject intensively, Mr Andrae said.

In a post on a chatroom website, which has since been taken down, a former classmate wrote of how schoolchildren would harrass and bully Sonboly.

Mr Andrae said Sonboly had a fascination with the neo-Nazi Anders Breivik, who murdered 77 people in a killing spree in Oslo. The Munich shootings occurred on the fifth anniversary of the Norway massacre.