Brusthom Ziamani was found guilty last month of preparing an 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.
Also Read
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'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.