|
1 | 1 | /* |
2 | | - * Copyright 2002-2016 the original author or authors. |
| 2 | + * Copyright 2002-2018 the original author or authors. |
3 | 3 | * |
4 | 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
5 | 5 | * you may not use this file except in compliance with the License. |
@@ -169,6 +169,20 @@ class KotlinAutowiredTests { |
169 | 169 | assertEquals(tb, kb.testBean) |
170 | 170 | } |
171 | 171 |
|
| 172 | + @Test // SPR-16289 |
| 173 | + fun `Instantiation via secondary constructor when a default primary is defined`() { |
| 174 | + val bf = DefaultListableBeanFactory() |
| 175 | + val bpp = AutowiredAnnotationBeanPostProcessor() |
| 176 | + bpp.setBeanFactory(bf) |
| 177 | + bf.addBeanPostProcessor(bpp) |
| 178 | + val bd = RootBeanDefinition(KotlinBeanWithPrimaryAndSecondaryConstructors::class.java) |
| 179 | + bd.scope = RootBeanDefinition.SCOPE_PROTOTYPE |
| 180 | + bf.registerBeanDefinition("bean", bd) |
| 181 | + |
| 182 | + bf.getBean(KotlinBeanWithPrimaryAndSecondaryConstructors::class.java, "foo") |
| 183 | + bf.getBean(KotlinBeanWithPrimaryAndSecondaryConstructors::class.java) |
| 184 | + } |
| 185 | + |
172 | 186 | @Test(expected = BeanCreationException::class) // SPR-16022 |
173 | 187 | fun `No autowiring with primary and secondary non annotated constructors`() { |
174 | 188 | val bf = DefaultListableBeanFactory() |
@@ -244,6 +258,11 @@ class KotlinAutowiredTests { |
244 | 258 | constructor() : this(TestBean()) |
245 | 259 | } |
246 | 260 |
|
| 261 | + @Suppress("unused", "UNUSED_PARAMETER") |
| 262 | + class KotlinBeanWithPrimaryAndSecondaryConstructors() { |
| 263 | + constructor(p: String) : this() |
| 264 | + } |
| 265 | + |
247 | 266 | class KotlinBeanWithSecondaryConstructor( |
248 | 267 | val optional: String = "foo", |
249 | 268 | val injectedFromConstructor: TestBean |
|
0 commit comments