We build a dynamic capital structure model to study the link between systematic risk exposure and debt maturity, as well as their joint impact on the term structure of credit spreads. Our model allows for time variation and lumpiness in the maturity structure. Relative to short-term debt, long-term debt is less prone to rollover risks, but its illiquidity raises the costs of financing. The risk premium embedded in the bankruptcy costs causes firms with high systematic risk to favour longer debt maturity, as well as a more stable maturity structure over the business cycle. Pro-cyclical debt maturity amplifies the impact of aggregate shocks on the term structure of credit spreads, especially for firms with high leverage or high beta, and for firms with a large amount of long-term debt maturing when the aggregate shock arrives. However, endogenous maturity choice can also reduce and even reverse the effect of rollover risk on credit spreads. We provide empirical evidence for the model predictions on both debt maturity and credit spreads.