Error injecting mybatis mapper in spring using Intellij IDEA - intellij-idea

I configure it like this in the application-context.xml
<mybatis:scan base-package="com.db"/>
And add #Component for the mapper interface.
#Component
public interface MenuMapper {}
And autowire it like this.
#Autowired
MenuMapper menuMapper;
It generates errors in IDEA.
The error is
No beans of type MenuMapper found.

Add #Repository to your MenuMapper interface

This because mybatis set bean definition class as MapperFactoryBean, so it's not able to find type of mapper. You can use #Resource replace #Autowired. See ClassPathMapperScanner for detail.

Related

No bean exists of type error in Kotlin-micronaut

I have a class which creates custom-named bean (test-index), but if I try to change the name of the bean to some other name (say test-index-new), it results in following error whereas the same works if the bean name is not changed:
Code:
#Singleton
#Requires("data-source-config.files-to-load.bigram-corpus")
class Service(
#Named("test-index") val biGramIndexManagerService: BigramIndexManagerService // changing it to test-index-new results in below error
)
BigramIndexManagerService.kt
class BigramIndexManagerService {
// business-service class
}
No bean of type exists for the given qualifier: #Named('test-index-new'): Make sure the bean is not disabled by bean requirements (enable trace logging for 'io.micronaut.context.condition' to check) and if the bean is enabled then ensure the class is declared a bean and annotation processing is enabled (for Java and Kotlin the 'micronaut-inject-java' dependency should be configured as an annotation processor).
I have enabled annotation processing at dependencies.gradle like below:
annotationProcessor "io.micronaut:micronaut-inject-java"
And I have bigram-corpus at the application.yml file
data-source-config:
files-to-load:
bigram-corpus:
file-path: <file_path>
....
Please let me know if I am missing something, thanks in advance!
After doing clean build, the issue has been fixed. Whoever encounters this issue, please do a delete of your build folder and run it again or do a clean build. Hope this helps!

Flowable delegateExpression in service task is not working

The flowable version which I'm using is 6.4.1.
#Component
public class MyClass implements JavaDelegate {
#Autowired
private MySampleService mySampleService;
#Override
public void execute(DelegateExecution delegateExecution){
sampleService.doSomeTask();
}
}
Here, myClass bean would be created for class MyClass. Hence, in the bpmn, I can use it like flowable:delegateExpression="${myClass}".
But I'm getting error
"unknown property used in expression: ${myClass}"
And without delegateExpression, mySampleService would be null.
Any suggestions?
There are two ways to configure flowable:
Manually - When using ‘regular’ Spring, you also need to register the ProcessEngineFactoryBean. This will take the engineConfiguration and create a SpringExpressionManager (https://github.com/flowable/flowable-engine/blob/master/modules/flowable-spring/src/main/java/org/flowable/spring/SpringExpressionManager.java) that has access to the expression manager.
SpringBoot, provides out of the box configuration. One only need to provide the needed beans, like DataSource, AsyncExecutor, etc. (based on you the scenario) and spring boot will take care of the rest.

Error while setting up Spring Data JPA Read-Only Repository

Spring Boot: 1.3.0.RC1
Spring Boot Starter JPA: 1.3.0.RC1
Having an issue with setting up a Spring Data JPA Read Only Repository.
#NoRepositoryBean
public interface ReadOnlyRepository<T, ID extends Serializable> extends Repository<T, ID> {
T findOne(ID id);
Iterable<T> findAll();
Iterable<T> findAll(Sort sort);
Page<T> findAll(Pageable pageable);
}
Using IntelliJ 15 I am getting this compile error:
Error:(16, 83) java: type org.springframework.stereotype.Repository does not take parameters
The error points at this bit of code: Repository<T, ID>
Has something changed within Spring Data JPA? Am I doing something wrong?
Following examples as listed here: Fine-tuning Spring Data repositories
The error points in the right direction. IntelliJ 15 when using ctrl space pulls the Repository Stereotype import org.springframework.stereotype.Repository rather than the correct import org.springframework.data.repository.
If you type quickly and don't notice the wrong import you will receive the error above.

Grails test and #Transactional

I have Grails test:
class GormTests extends GroovyTestCase {
static transactional = false
...
}
I'm trying to mark method as transactional by org.springframework.transaction.annotation.Transactional annotation but following exception arises:
org.springframework.aop.framework.AopConfigException: Could not generate CGLIB subclass of class [class GormTests]: Common causes of this problem include using a final class or a non-visible class; nested exception is net.sf.cglib.core.CodeGenerationException: java.lang.reflect.InvocationTargetException-->null
How can I fix it?
#Transactional is only for Spring beans - test classes aren't beans. Your best bet is to split the test class into two, one with non-transactional tests and one with.

Apache Shiro EhCache initialization exception: Another unnamed CacheManager already exists in the same VM

I am trying to get EhCache configured to handle authorization caching in my Apache Shiro enabled web service. Currently I am getting the following exception:
org.apache.shiro.cache.CacheException: net.sf.ehcache.CacheException: Another unnamed CacheManager already exists in the same VM. Please provide unique names for each CacheManager in the config or do one of following:
Use one of the CacheManager.create() static factory methods to reuse same CacheManager with same name or create one if necessary
Shutdown the earlier cacheManager before creating new one with same name.
My shiro.ini looks like:
[main]
...
cacheManager = org.apache.shiro.cache.ehcache.EhCacheManager
cacheManager.cacheManagerConfigFile = classpath:ehcache.xml
securityManager.cacheManager = $cacheManager
From this StackOverflow post it looks like people using Spring have gotten around this issue by forcing the CacheManager to be a singleton: Another unnamed CacheManager already exists in the same VM (ehCache 2.5).
Is anybody aware of work-arounds not using Spring initialization (I'm working within the dropwizard framework and have no need to pull in Spring)? Is there some manner of enforcing singleton configuration from the shiro.ini?
Thank you in advance!
Create a custom class that extends EhCacheManager and set your cacheManager in the constructor. This (net.sf.ehcache.CacheManager.create()) allows you to reuse an already existing cachemanager.
package lekkie.omotayo
public class MyShiroCacheManager extends EhCacheManager
{
public CacheManager()
{
setCacheManager(net.sf.ehcache.CacheManager.create());
}
}
Then you can do this:
cacheManager = lekkie.omotayo.MyShiroCacheManager
cacheManager.cacheManagerConfigFile = classpath:ehcache.xml
securityManager.cacheManager = $cacheManager