3
  1. @EnableTransactionManagement is added on MyBootApplication
  2. @Bean public Object testBean(PlatformTransactionManager platformTransactionManager){ System.out.println(">>>>>>>>>>TransactionManager is " + platformTransactionManager.getClass().getName()); return new Object(); } it print TransactionManager is org.springframework.orm.jpa.JpaTransactionManager
  3. @Service open class UserService : BaseService() { @Autowired lateinit var repository: UserRepository @Transactional fun updateValid(id: Long, valid: Boolean) { ErrorConstant.ParamErrorCode.IdIsNull.caseThrow { id == 0.toLong() } repository.updateValid(id,valid) } }

i use spring.boot to build my project.

when i remove the @Transactional,everything is fine .

but when i add it. the repository is null,it can't be inject.

i read that question Using @Transaction annotation with @Autowired - Spring ,and i add spring.aop.proxy-target-class=true in my application.properties ,still same error .

i use kotlin to write it,but i guess this is not the reason.

even so ,i will try with java later .

My mistake , I have some properties in BaseService , should add open on it too .

JsonSong
  • 328
  • 2
  • 14
  • I had the same problem because I used @Transactional from javax.transaction package. After change to org.springframework.transaction.annotation it works. – Lukas M. Sep 27 '17 at 11:01
  • Maybe duplicate to https://stackoverflow.com/questions/41298289/spring-boot-autowired-with-kotlin-in-service-is-always-null – miran Jan 03 '18 at 16:07

2 Answers2

1

I have added 'open' on func yet ,but leave out the propeties .

@PersistenceContext
protected open lateinit var em: EntityManager

@Autowired
protected open lateinit var env: Environment
JsonSong
  • 328
  • 2
  • 14
1

For others that might miss the resolution in bold at the bottom of the question: All public functions should be set to open (in oppose to the implicit final default in kotlin)

itavq
  • 135
  • 9