Reputation: 348
@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@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 .
Upvotes: 3
Views: 1602
Reputation: 135
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)
Upvotes: 1
Reputation: 348
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
Upvotes: 1