What is package-info.java and how can I add it to my project?

Is used to store javadoc description. You can find it at 7.4.1. Named Packages of the The Java® Language Specification: It is recommended that package-info.java, if it is present, take the place of package.html for javadoc and other similar documentation generation systems. If this file is present, the documentation generation tool should look for the … Read more

Use abstract super class as parameter for Spring data repository

If you aren’t using table inheritance on the database side (e.g. super class table with descriminator column), AFAIK, and based off reading the JPA tutorial, this can’t be done (i.e. simply using @MappedSuperclass annotation for your abstract class) Mapped superclasses cannot be queried and cannot be used in EntityManager or Query operations. You must use … Read more

Autowire a bean within Spring’s Java configuration

If you need a reference to the DataSource bean within the same @Configuration file, just invoke the bean method. @Bean public OtherBean someOtherBean() { return new OtherBean(dataSource()); } or have it autowired into the @Bean method @Bean public OtherBean someOtherBean(DataSource dataSource) { return new OtherBean(dataSource); } The lifecycle of a @Configuration class sometimes prevents autowiring … Read more

Follow 302 redirect using Spring restTemplate?

Using the default ClientHttpRequestFactory implementation – which is the SimpleClientHttpRequestFactory – the default behaviour is to follow the URL of the location header (for responses with status codes 3xx) – but only if the initial request was a GETrequest. Details can be found in this class – searching for the following method: protected void prepareConnection(HttpURLConnection … Read more

Execution of JMS message listener failed, and no ErrorHandler has been set

There is a property on AbstractMessageListenerContainer: <bean id=”listener” class=”org.springframework.jms.listener.DefaultMessageListenerContainer”> <property name=”errorHandler” ref=”someHandler”/> <property name=”destinationName” value=”someQueue”/> <property name=”connectionFactory” ref=”connectionFactory”/> </bean> Where someHandler is a bean implementing ErrorHandler: @Service public class SomeHandler implements ErrorHandler { @Override public void handleError(Throwable t) { log.error(“Error in listener”, t); } } However note that according to the documentation: The default behavior … Read more

Spring Service default scope

Which is the default scope of a Spring 4 @Service? The default scope is singleton It is reasonable to design a Service implementation in order to store some info, related to the current logged user (according to the current HTTP session) Yes. In that case, the service will have to have the scope “session”. See … Read more

How to generate a dynamic “in (…)” sql list through Spring JdbcTemplate?

Yes, it’s possible in Spring if you use NamedParameterJdbcTemplate or SimpleJdbcTemplate with named parameters. List parameter can be set as a java.util.List: List<String> list = new ArrayList<String>(); list.add(“A”); list.add(“B”); list.add(“C”); List<SomeObject> result = simpleJdbcTemplate.query(“SELECT * FROM t WHERE c in (:list)”, new RowMapper<SomeObject>() { … }, Collections.singletonMap(“list”, list)); In this case Spring internally creates the … Read more

Spring @RequestBody containing a list of different types (but same interface)

You should use the Jackson annotations @JsonTypeInfo and @JsonSubTypes to achieve polymorphic json. The annotations go on the Animal base class. @JsonTypeInfo(use = Id.NAME, include = As.PROPERTY, property = “type”) @JsonSubTypes({@JsonSubTypes.Type(value = Dog.class, name = “Dog”), @JsonSubTypes.Type(value = Cat.class, name = “Cat”)}) public abstract class Animal { }

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)