I have spring+jpa+rest application on spring-boot(try to implement)
Application for spring-boot:
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.autoconfigure.domain.EntityScan;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.ImportResource;
import org.springframework.data.jpa.repository.config.EnableJpaRepositories;
import javax.persistence.PersistenceContext;
@SpringBootApplication
@ComponentScan("package")
@EnableJpaRepositories(basePackages = "package.dao", entityManagerFactoryRef = "emf")
@ImportResource("applicationContext.xml")
public class Application {
public static void main(String[] args) {
SpringApplication.run(Application.class, args);
}
}
I have rest - controller
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import package.myService;
@RestController
public class TestController {
@Autowired
private MyService myService;
@PostMapping("create")
public void test1(){
}
@PostMapping("{id}")
public void test2(@RequestBody Object object){
}
@GetMapping("{id}")
public void test3(@PathVariable Long id){
}
}
Entity:
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import java.math.BigDecimal;
@Entity
public class MyEntity {
@Id
@GeneratedValue
private Long id;
private String name;
public MyEntity() {
}
public MyEntity(Long id, String name) {
this.id = id;
this.name = name;
}
public Long getId() {
return id;
}
public void setId(Long id) {
this.id = id;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
}
Repository is:
MyEntityRepository:
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;
import org.springframework.stereotype.Repository;
@Repository
public interface MyEntityRepositoryextends JpaRepository<myEntity, Long>{
public void findNameById(@Param("id") Long id);
}
application context in resouces:
<?xml version="1.0" encoding="UTF-8" ?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:task="http://www.springframework.org/schema/task"
xmlns:util="http://www.springframework.org/schema/util"
xmlns:context="http://www.springframework.org/schema/context" xmlns:tx="http://www.springframework.org/schema/tx"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-4.3.xsd
http://www.springframework.org/schema/task
http://www.springframework.org/schema/task/spring-task-4.3.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context.xsd
http://www.springframework.org/schema/util
http://www.springframework.org/schema/util/spring-util-4.3.xsd
http://www.springframework.org/schema/security http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx.xsd">
<context:annotation-config />
<bean id="riskMetricService" class="ru.sbrf.risks.services.data.service.RiskMetricServiceImpl"/>
</beans>
If needs, I can add pom.xml
I have error message when try to strat: APPLICATION FAILED TO START
Description:
Parameter 0 of constructor in org.springframework.data.rest.webmvc.RepositorySearchController required a bean named 'emf' that could not be found.
Action:
Where need to locate file with dbconnection configs? How to solve this error message?