These are chat archives for spring-cloud/spring-cloud

4th
Jan 2018
Andrew Fitzgerald
@fitzoh
Jan 04 2018 05:05
This message was deleted
liubo404
@liubo404
Jan 04 2018 08:21

@NoRepositoryBean
public interface BaseRepository<T, ID extends Serializable> extends Repository<T, ID> {

    Optional<T> deleteById(ID id);

    public List<T> findByAttributeContainsText(String attributeName, String text);
}


public class BaseRepositoryImpl<T, ID extends Serializable>
        extends SimpleJpaRepository<T, ID> implements BaseRepository<T, ID> {

    private final EntityManager entityManager;

    public BaseRepositoryImpl(JpaEntityInformation entityInformation,  EntityManager entityManager) {
        super(entityInformation, entityManager);
        this.entityManager = entityManager;
    }

    @Transactional
    @Override
    public Optional<T> deleteById(ID id) {
        T deleted = entityManager.find(this.getDomainClass(), id);
        Optional<T> returned = Optional.empty();

        if (deleted != null) {
            entityManager.remove(deleted);
            returned = Optional.of(deleted);
        }
        return returned;
    }

    @Transactional
    @Override
    public List<T> findByAttributeContainsText(String attributeName, String text) {
        CriteriaBuilder builder = entityManager.getCriteriaBuilder();
        CriteriaQuery<T> cQuery = builder.createQuery(getDomainClass());
        Root<T> root = cQuery.from(getDomainClass());
        cQuery
                .select(root)
                .where(builder
                        .like(root.<String>get(attributeName), "%" + text + "%"));
        TypedQuery<T> query = entityManager.createQuery(cQuery);
        return query.getResultList();
    }
}

public interface TodoRepository  extends BaseRepository<Todo, Integer> {}

java.lang.IllegalStateException: Failed to load ApplicationContext
Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'todoRepository': Invocation of init method failed; nested exception is java.lang.IllegalArgumentException: Failed to create query method public abstract java.util.List xxx.com.tutorial.common.BaseRepository.findByAttributeContainsText(java.lang.String,java.lang.String)! No property attributeContainsText found for type Todo!
Caused by: org.springframework.data.mapping.PropertyReferenceException: No property attributeContainsText found for type Todo!
Caused by: org.springframework.data.mapping.PropertyReferenceException: No property attributeContainsText found for type Todo!
I have created a customized base jpa repository, But I get this error
MohanJagadheeswaran
@MohanJagadheeswaran
Jan 04 2018 20:02
Hi guys
iam trying to run Spring boot web application with @Enabletask annotation in my main class.
iam getting Closing org.springframework.boot.context.embedded.AnnotationConfigEmbeddedWebApplicationContext@20ccf40b: startup date [Fri Jan 05 01:29:03 IST 2018]; root of context hierarchy
I could't find the issue
can we run the application in embedded tomcat?
I added Springcloudtask dependencies to my existing spring batch application
And @EnableTask annotation to my main class.
Do we need to to any more configs?
Dave Syer
@dsyer
Jan 04 2018 22:19
You might want to add spring.cloud.task.closecontextEnabled=false if your app is long lived (it is not the default)
I don't really understand why that is not the default. You could take it up in github if you want to argue that way.