Eu sou novo para a primavera-boot. Depois que me mudei uma classe de pacote diferente (outro aquele contém 'aplicação'), Não foi possível instanciar a classe bean: Nenhum construtor padrão encontrado exceção é gerada.
Antes (código viável)
package com.server;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Profile;
import org.springframework.stereotype.Controller;
@Configuration
@ComponentScan(basePackages = {com.server })
@EnableAutoConfiguration
@Profile({ default })
@Controller
public class Application {
private static Log logger = LogFactory.getLog(Application.class);
public static void main(String[] args) {
logger.info(Starting Application...);
SpringApplication.run(Application.class, args);
}
}
Um pedaço de código de http://bitwiseor.com/2013/09/20/creating-test-services-with-spring-boot/
package com.server;
import java.util.Collections;
import javax.sql.DataSource;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Configuration;
import org.springframework.dao.EmptyResultDataAccessException;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.stereotype.Component;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
@Configuration
@Controller
@Profile({ default })
class Franchise {
private JdbcTemplate jdbcTemplate;
@Autowired
public Franchise(DataSource dataSource) {
this.jdbcTemplate = new JdbcTemplate(dataSource);
}
@ResponseBody
@RequestMapping(/api/franchise/{id})
String franchiseId(@PathVariable Long id) {
try {
return jdbcTemplate.queryForMap(SELECT id, title FROM franchises WHERE id=?, id).toString();
} catch(EmptyResultDataAccessException ex) {
return Collections.EMPTY_MAP.toString();
}
}
@ResponseBody
@RequestMapping(/api/franchise)
String franchises() {
try {
return jdbcTemplate.queryForList(SELECT id, title FROM franchises).toString();
} catch(EmptyResultDataAccessException ex) {
return Collections.EMPTY_MAP.toString();
}
}
}
Eu sou capaz de abrir o servidor quando a classe 'Aplicação' e 'franquia' estão localizados no mesmo pacote. No entanto, quando me mudei para a classe 'Franchise' em outro pacote, como mostrado abaixo, eu tenho essa exceção: não foi possível instanciar a classe bean: Nenhum construtor padrão encontrado exceção é gerada.
package com.server.api;
import java.util.Collections;
import javax.sql.DataSource;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Configuration;
import org.springframework.dao.EmptyResultDataAccessException;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.stereotype.Component;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
@Configuration
@Controller
@Profile({ default })
class Franchise {
private JdbcTemplate jdbcTemplate;
@Autowired
public Franchise(DataSource dataSource) {
this.jdbcTemplate = new JdbcTemplate(dataSource);
}
@ResponseBody
@RequestMapping(/api/franchise/{id})
String franchiseId(@PathVariable Long id) {
try {
return jdbcTemplate.queryForMap(SELECT id, title FROM franchises WHERE id=?, id).toString();
} catch(EmptyResultDataAccessException ex) {
return Collections.EMPTY_MAP.toString();
}
}
@ResponseBody
@RequestMapping(/api/franchise)
String franchises() {
try {
return jdbcTemplate.queryForList(SELECT id, title FROM franchises).toString();
} catch(EmptyResultDataAccessException ex) {
return Collections.EMPTY_MAP.toString();
}
}
}
Como posso resolver este problema se eu queria mudar essa classe em um pacote diferente?
Obrigado!
Edit: Eu encontrei uma solução Quando eu removi o seguinte tag, eu sou capaz de colocar a classe em pacote separado. @Configuration @profile ({ default})
Mas eu não tenho idéia porque ...













