2017-04-03 56 views
2

我有一個使用JPA和HSQLDB數據持久化一個簡單的Spring啓動的基於Web的應用程序,但現在當我嘗試建立我的項目,它失敗並說:春季啓動 - 無豆名爲「entityManagerFactory的」可用

No bean named 'entityManagerFactory' available 

我的代碼如下:

應用

import org.springframework.boot.SpringApplication; 
import org.springframework.boot.autoconfigure.SpringBootApplication; 
import org.springframework.scheduling.annotation.EnableScheduling; 

@SpringBootApplication 
@EnableScheduling 
public class Application { 

    public static void main(String[] args) { 
     SpringApplication.run(Application.class, args); 
    } 
} 

「Comentario」 表

package dashboard.model; 

import java.util.Date; 

import javax.persistence.*; 

@Entity 
@Table(name="TComentarios") 
public class Comentario { 

    @Id 
    @GeneratedValue(strategy = GenerationType.IDENTITY) 
    private Long id; 
    private String contenido; 
    @ManyToOne 
    private Sugerencia sugerencia; 
    @ManyToOne 
    private Usuario usuario; 
    @Temporal(TemporalType.DATE) 
    private Date fecha; 

    Comentario(){} 

    get/set... 
} 

import java.util.List; 

import org.springframework.data.jpa.repository.JpaRepository; 
import org.springframework.data.jpa.repository.Query; 
import org.springframework.stereotype.Repository; 

@Repository 
public interface ComentarioRepository extends JpaRepository<Comentario, Long>{ 
@Query("select c from Comentario c where c.sugerencia = ?1") 
List<Comentario> findBySugerencia(Sugerencia sugerencia); 
} 

的pom.xml(依賴部分):

<parent> 
    <groupId>org.springframework.boot</groupId> 
    <artifactId>spring-boot-starter-parent</artifactId> 
    <version>1.4.4.RELEASE</version> 
</parent> 

<dependencies> 
    <dependency> 
     <groupId>org.springframework.boot</groupId> 
     <artifactId>spring-boot-starter-web</artifactId> 
    </dependency> 

    <dependency> 
     <groupId>org.springframework.boot</groupId> 
     <artifactId>spring-boot-starter-test</artifactId> 
     <scope>test</scope> 
    </dependency> 

    <dependency> 
     <groupId>org.springframework.boot</groupId> 
     <artifactId>spring-boot-starter-data-rest</artifactId> 
    </dependency> 

    <dependency> 
     <groupId>org.springframework.boot</groupId> 
     <artifactId>spring-boot-devtools</artifactId> 
     <optional>true</optional> 
    </dependency> 

    <dependency> 
     <groupId>org.springframework.boot</groupId> 
     <artifactId>spring-boot-starter-thymeleaf</artifactId> 
    </dependency> 

    <dependency> 
     <groupId>org.springframework.boot</groupId> 
     <artifactId>spring-boot-starter-data-jpa</artifactId> 
     <version>1.5.2.RELEASE</version> 
    </dependency> 

    <dependency> 
     <groupId>org.hsqldb</groupId> 
     <artifactId>hsqldb</artifactId> 
    </dependency> 

    <dependency> 
     <groupId>org.springframework.cloud</groupId> 
     <artifactId>spring-cloud-starter-bus-kafka</artifactId> 
     <version>1.2.2.RELEASE</version> 
    </dependency> 

    <dependency> 
     <groupId>org.springframework.boot</groupId> 
     <artifactId>spring-boot-starter-websocket</artifactId> 
    </dependency> 

    <dependency> 
     <groupId>org.webjars</groupId> 
     <artifactId>webjars-locator</artifactId> 
    </dependency> 

    <dependency> 
     <groupId>org.webjars</groupId> 
     <artifactId>sockjs-client</artifactId> 
     <version>1.0.2</version> 
    </dependency> 

    <dependency> 
     <groupId>org.webjars</groupId> 
     <artifactId>stomp-websocket</artifactId> 
     <version>2.3.3</version> 
    </dependency> 

    <dependency> 
     <groupId>org.webjars</groupId> 
     <artifactId>jquery</artifactId> 
     <version>3.2.0</version><!--$NO-MVN-MAN-VER$--> 
    </dependency> 

    <dependency> 
     <groupId>com.fasterxml.jackson.dataformat</groupId> 
     <artifactId>jackson-dataformat-xml</artifactId> 
    </dependency> 

    <dependency> 
     <groupId>org.codehaus.woodstox</groupId> 
     <artifactId>woodstox-core-asl</artifactId> 
     <version>4.4.1</version> 
    </dependency> 

</dependencies> 
+0

初學者停止混合彈簧啓動版本(1.4.4和1.5.2)... –

回答

0

它將也許不能解決你的問題,但覆蓋神器的依賴版本由彈簧引導起動拉不建議使用pom,可能會產生副作用:

<parent> 
    <groupId>org.springframework.boot</groupId> 
    <artifactId>spring-boot-starter-parent</artifactId> 
    <version>1.4.4.RELEASE</version> 
</parent>  
....  
<dependency> 
     <groupId>org.springframework.boot</groupId> 
     <artifactId>spring-boot-starter-data-jpa</artifactId> 
     <version>1.5.2.RELEASE</version> 
</dependency> 

它肩膀d是不夠的:

<dependency> 
     <groupId>org.springframework.boot</groupId> 
     <artifactId>spring-boot-starter-data-jpa</artifactId> 
</dependency> 

確實大部分由啓動POM拉依賴,但它仍然是屬於org.springframework.boot的groupId被設計使用相同版本的工作依賴更真實。

+0

它不起作用 –

+0

對不起。正如答案中提到的那樣,它可能無法正常工作,但在實際配置中需要考慮。當你的第一個問題將被解決時,你可能會有不好的驚喜。我只是試圖重現你的問題,但我沒有。你能用所有的堆棧跟蹤來編輯你的問題嗎? – davidxxx

+0

是的,但奇怪的是,在特拉維斯它不會失敗,但在本地是 –