package com.hb;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.jpa.repository.config.EnableJpaRepositories;
import org.springframework.stereotype.Repository;
@Repository
@EnableJpaRepositories
public interface **CurrencyExchangeRepository** extends JpaRepository<CurrencyConversion, Long> {
//Now we can use JpaRepository’s methods: save(), findOne(), findById(), findAll(), count(), delete(), deleteById()…
// without implementing these methods.
@Query("SELECT value FROM currency_conversion t WHERE t.from_country = ?1 and t.to_country = ?2")
CurrencyConversion getCurrencyValue(String fromCurrency, String toCurrency);
}
package com.hb;
import java.math.BigDecimal;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.cloud.context.config.annotation.RefreshScope;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RestController;
@RefreshScope
@RestController
public class **CurrencyExchangeSampleController** {
@Autowired
CurrencyExchangeRepository repo;
@GetMapping("/chenna")
public String msg(){
return "hello chenna";
}
@GetMapping("/currency-exchange-service/fromCurrency/{fromCurrency}/toCurrency/{toCurrency}")
public ExchangeValue retrieveExchangeValue(@PathVariable String fromCurrency,
@PathVariable String toCurrency) {
System.out.println("msg : " + msg);
CurrencyConversion cc = impl.getCurrencyValue(fromCurrency, toCurrency);
System.out.println("value : " + cc.getValue());
}
}
package com.hb;
@SpringBootApplication
@EnableDiscoveryClient
@EnableAutoConfiguration(exclude={DataSourceAutoConfiguration.class})
@ComponentScan("com.hb")
public class **CurrencyExchangeServiceSampleApplication** {
public static void main(String[] args)
{
SpringApplication.run(
CurrencyExchangeServiceSampleApplication.class,
args);
}
}
this is my code and i am getting below error
APPLICATION FAILED TO START
Description:
Field repo in com.hb.CurrencyExchangeSampleController required a bean of type 'com.hb.CurrencyExchangeRepository' that could not be found.
The injection point has the following annotations: - @org.springframework.beans.factory.annotation.Autowired(required=true)
Action:
Consider defining a bean of type 'com.hb.CurrencyExchangeRepository' in your configuration.
Disconnected from the target VM, address: '127.0.0.1:53276', transport: 'socket'
Process finished with exit code 0