Brusthom Ziamani was found guilty last month of preparing n act of terrorism.
The Old Bailey court in London was told how he was inspired by the murder of Fusilier Lee Rigby on the streets of
London in May 2013 and used the internet to research cadet bases.
He converted to Islam in 2014 and became radicalised.
Months later he was arrested in east London in possession of a 12-inch knife and a hammer.
Ziamani, who was held on August 19, last year as part of a joint police and MI5 intelligence operation, also had a black "Islamic flag" in his bag.
Police say he visited his former girlfriend earlier that day, when he showed her his weapons and told her he intended to attack and kill soldiers.
Judge Timothy Pontius told Ziamani: "A realistic and sensible assessment of the whole of the evidence leads inescapably to the conclusion that this defendant, had he not by sheer good fortune been spotted and stopped by the police on the street in east London, would have carried out the intention he had so graphically expressed to his ex-girlfriend just a few hours before."
He said Ziamani would have to serve at least two-thirds of his sentence before being eligible for parole.
Ziamani was born in London to Congolese parents. His mother worked as a nursery nurse and his father was a psychiatric nurse.
Ziamani's lawyer, Naeem Mian, said his client was not an "entrenched extremist" but a young man who while destitute had been groomed by people who were "more sophisticated and mature" than him.
Raveena Tandon's CHILLY vacation
'If Modi lives up to his promises, his past does not matter'
Stunning PHOTOS of a rare solar eclipse
Chance for Saina to avenge All England defeat to Marin at Indian Open
Cairn India's mounting troubles