我正在制作一个angular + spring应用程序,并试图将其部署在同一服务器上。当我分别创建后端时,它在所有过程中均正常运行。但是当我在spring项目中复制我的角度项目并在pom.xml中配置并更新了我的maven并尝试运行该项目时,它开始给我以下错误
. ____ _ __ _ _
/\\ / ___'_ __ _ _(_)_ __ __ _ \ \ \ \
( ( )\___ | '_ | '_| | '_ \/ _` | \ \ \ \
\\/ ___)| |_)| | | | | || (_| | ) ) ) )
' |____| .__|_| |_|_| |_\__, | / / / /
=========|_|==============|___/=/_/_/_/
:: Spring Boot :: (v2.1.8.RELEASE)
2019-09-24 16:13:29.074 INFO 3136 --- [ main]
com.accounts.rtgsneft.Application : Starting Application on HO-W-
Ankushpc with PID 3136 (D:\Rocky\workspaces\acounts-projects\rtgs-neft-
v1.0\target\classes started by Rocky in D:\Rocky\workspaces\acounts-
projects\rtgs-neft-v1.0)
2019-09-24 16:13:29.076 INFO 3136 --- [ main]
com.accounts.rtgsneft.Application : No active profile set, falling
back to default profiles: default
2019-09-24 16:13:29.530 INFO 3136 --- [ main]
.s.d.r.c.RepositoryConfigurationDelegate : Bootstrapping Spring Data
repositories in DEFAULT mode.
2019-09-24 16:13:29.584 INFO 3136 --- [ main] .
s.d.r.c.RepositoryConfigurationDelegate : Finished Spring Data repository
scanning in 48ms. Found 4 repository interfaces.
2019-09-24 16:13:29.910 INFO 3136 --- [ main]
trationDelegate$BeanPostProcessorChecker : Bean
'org.springframework.hateoas.config.HateoasConfiguration' of type [org.springframework.hateoas.config.HateoasConfiguration$$EnhancerBySpringCGLIB$$3c9c44bd] is not eligible for getting processed by all BeanPostProcessors (for example: not eligible for auto-proxying)
2019-09-24 16:13:30.143 INFO 3136 --- [ main] o.s.b.w.embedded.tomcat.TomcatWebServer : Tomcat initialized with port(s): 8086 (http)
2019-09-24 16:13:30.160 INFO 3136 --- [ main] o.apache.catalina.core.StandardService : Starting service [Tomcat]
2019-09-24 16:13:30.160 INFO 3136 --- [ main] org.apache.catalina.core.StandardEngine : Starting Servlet engine: [Apache Tomcat/9.0.24]
2019-09-24 16:13:30.264 INFO 3136 --- [ main] o.a.c.c.C.[Tomcat].[localhost].[/] : Initializing Spring embedded WebApplicationContext
2019-09-24 16:13:30.264 INFO 3136 --- [ main] o.s.web.context.ContextLoader : Root WebApplicationContext: initialization completed in 1158 ms
2019-09-24 16:13:30.399 WARN 3136 --- [ main] ConfigServletWebServerApplicationContext : Exception encountered during context initialization - cancelling refresh attempt: org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'beneficiaryController': Unsatisfied dependency expressed through field 'beneficiaryService'; nested exception is org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'beneficiaryMasterServiceImpl': Unsatisfied dependency expressed through field 'beneficiaryRepo'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'beneficiaryMasterRepository': Cannot create inner bean '(inner bean)#3ac04654' of type [org.springframework.orm.jpa.SharedEntityManagerCreator] while setting bean property 'entityManager'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name '(inner bean)#3ac04654': Cannot resolve reference to bean 'entityManagerFactory' while setting constructor argument; nested exception is org.springframework.beans.factory.NoSuchBeanDefinitionException: No bean named 'entityManagerFactory' available
2019-09-24 16:13:30.402 INFO 3136 --- [ main] o.apache.catalina.core.StandardService : Stopping service [Tomcat]
2019-09-24 16:13:30.416 INFO 3136 --- [ main] ConditionEvaluationReportLoggingListener :
Error starting ApplicationContext. To display the conditions report re-run
your application with 'debug' enabled.
2019-09-24 16:13:30.465 ERROR 3136 --- [ main] o.s.b.d.LoggingFailureAnalysisReporter :
***************************
APPLICATION FAILED TO START
***************************
Description:
Field beneficiaryRepo in
com.accounts.rtgsneft.service.BeneficiaryMasterServiceImpl required a bean
named 'entityManagerFactory' 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 named 'entityManagerFactory' in your configuration.
我已经尝试了所有堆栈上的解决方案,但是没有一个起作用。
这是我尝试过的解决方案:
Cannot resolve reference to bean 'entityManagerFactory' while setting constructor argument
Spring Boot - repository field required a bean named 'entityManagerFactory' that could not be found
Field repository required a bean named 'entityManagerFactory' that could not be found
这是我在调试时尝试的解决方案。
我的pom.xml
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0
http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.1.7.RELEASE</version>
<relativePath /> <!-- lookup parent from repository -->
</parent>
<groupId>com.accounts.rtgsneft</groupId>
<artifactId>rtgsneft</artifactId>
<version>0.0.1-SNAPSHOT</version>
<name>rtgsneft</name>
<description>Gold's Gym Account department rtgs neft software</description>
<properties>
<java.version>1.8</java.version>
</properties>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-jpa</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-rest</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-jdbc</artifactId>
</dependency>
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<scope>runtime</scope>
</dependency>
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<optional>true</optional>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
<plugin>
<artifactId>maven-resources-plugin</artifactId>
<executions>
<execution>
<id>copy-resources</id>
<phase>validate</phase>
<goals>
<goal>copy-resources</goal>
</goals>
<configuration>
<outputDirectory>${basedir}/src/main/resources/static/</outputDirectory>
<resources>
<resource>
<directory>${basedir}/src/main/rtgs-neft/dist/rtgs-neft</directory>
</resource>
</resources>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>
我的BeneficiaryController .java
package com.accounts.rtgsneft.controller;
import java.util.List;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.accounts.rtgsneft.model.BeneficiaryMaster;
import com.accounts.rtgsneft.service.BeneficiaryMasterService;
/**
* @author Rocky
*
*/
@CrossOrigin(origins = "*", maxAge = 3600)
@RestController
@RequestMapping("beneficiary")
public class BeneficiaryController {
@Autowired
BeneficiaryMasterService beneficiaryService;
@GetMapping("all-beneficiary")
public ResponseEntity<?> getBeneficiaries() {
List<BeneficiaryMaster> beneficiaries = beneficiaryService.gettingBeneficiaries();
return new ResponseEntity<>(beneficiaries, HttpStatus.OK);
}
@PostMapping("new-beneficiary")
public ResponseEntity<?> postBeneficiary(@RequestBody BeneficiaryMaster beneficiary) {
boolean beneficiaryRegistered = beneficiaryService.registerBeneficiary(beneficiary);
return new ResponseEntity<>(beneficiaryRegistered, HttpStatus.OK);
}
@PostMapping("single-beneficiary")
public ResponseEntity<?> selectedBeneficiary(@RequestBody BeneficiaryMaster beneficiaryOBJ) {
BeneficiaryMaster beneficiary = beneficiaryService.getBeneficiary(beneficiaryOBJ.getAccountNumber());
return new ResponseEntity<>(beneficiary, HttpStatus.OK);
}
}
我的BeneficiaryMasterService.java
package com.accounts.rtgsneft.service;
import java.util.List;
import com.accounts.rtgsneft.model.BeneficiaryMaster;
public interface BeneficiaryMasterService {
List<BeneficiaryMaster> gettingBeneficiaries();
boolean registerBeneficiary(BeneficiaryMaster beneficiary);
BeneficiaryMaster getBeneficiary(Long accountNumber);
}
我的BeneficiaryMasterServiceImpl.java
package com.accounts.rtgsneft.service;
import java.util.List;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.accounts.rtgsneft.model.BeneficiaryMaster;
import com.accounts.rtgsneft.repos.BeneficiaryMasterRepository;
@Service
public class BeneficiaryMasterServiceImpl implements BeneficiaryMasterService {
@Autowired
BeneficiaryMasterRepository beneficiaryRepo;
@Override
public List<BeneficiaryMaster> gettingBeneficiaries() {
return beneficiaryRepo.findAll();
}
@Override
public boolean registerBeneficiary(BeneficiaryMaster beneficiary) {
boolean benficiaryStatusFlag = false;
BeneficiaryMaster benficiaryStatus= beneficiaryRepo.save(beneficiary);
if(benficiaryStatus != null ) {
benficiaryStatusFlag = true;
}
return benficiaryStatusFlag;
}
@Override
public BeneficiaryMaster getBeneficiary(Long accountNumber) {
return beneficiaryRepo.getOne(accountNumber);
}
}
我的BeneficiaryMasterRepository.java
package com.accounts.rtgsneft.repos;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.stereotype.Repository;
import com.accounts.rtgsneft.model.BeneficiaryMaster;
@Repository
public interface BeneficiaryMasterRepository extends
JpaRepository<BeneficiaryMaster, Long> {}
我希望有足够的数据来找出问题所在。
如果还有其他解决方案,请推荐给我。 我正在使用Spring 2.17 我想在tomcat中部署应用程序war文件,在此之前,我必须对其进行测试以检查其是否仍在工作。
答案 0 :(得分:-1)
Spring Data JPA默认情况下会查找一个名为EntityManagerFactory的EntityManagerFactory。请查看EnableJpaRepositories的Javadoc的这一部分或Spring Data JPA文档的表2.1。
这意味着您必须将emf bean重命名为entityManagerFactory或将Spring配置更改为:
(如果您使用的是XML)
或
@EnableJpaRepositories(basePackages =“ your.package”,entityManagerFactoryRef =“ emf”)
(如果您使用的是Java Config)