关于在6-2关于红包收发之操作数据库(下)中的报错求解?
来源:7-1 关于事务:红包并发中的事务

feimin
2019-04-18
- 我的疑问是:视频里面廖师兄没有注释掉“获取红包列表”的@GetMapping方法,我也没有,但是我跑起来报错,报错信息大概是RequesMapping的路径重复存在,求教?
package com.imooc.luckmoney;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import java.math.BigDecimal;
import java.util.List;
/**
-
@author
-
@version 1.0
-
@date 2019/4/18 0:50
*/
@RestController
public class LuckmoneyController {@Autowired
private LuckmoneyRepository repository;/**
- 获取红包列表
*/
@GetMapping("/luckmoneys")
public List list(){
return repository.findAll();
}
/**
- 创建红包(发红包)
- /
@GetMapping("/luckmoneys")
public Luckmoney create(@RequestParam(“producer”) String producer,
@RequestParam(“money”) BigDecimal money){
Luckmoney luckmoney = new Luckmoney();
/*- 1.set和get用于private变量的封装,一般只用在封装里,当然它也可以用2所说的。
- 2.get和set起源于它的中文翻译,获取和设置。主要是便于理解。比如获取XX值和设置XX值。这样不仅方便自己看,别人也很容易理解的。所以也不仅仅用于封装的。
- 3.javabean就是一个简单的java类,里面只有变量和set/get方法之类的,不需要安装jar包及组件。
*/
luckmoney.setProducer(producer);
luckmoney.setMoney(money);
return repository.save(luckmoney);
}
/**
- 通过id查询红包
- */
/**
- 更新红包(领红包)
- */
}
- 获取红包列表
报错信息如下:
D:\Java\jdk1.8.0_131\bin\java -XX:TieredStopAtLevel=1 -noverify -Dspring.output.ansi.enabled=always -Dcom.sun.management.jmxremote -Dcom.sun.management.jmxremote.port=51287 -Dcom.sun.management.jmxremote.authenticate=false -Dcom.sun.management.jmxremote.ssl=false -Dspring.liveBeansView.mbeanDomain -Dspring.application.admin.enabled=true “-javaagent:D:\ProgramFiles\JetBrains\IntelliJ IDEA 2017.2\lib\idea_rt.jar=51288:D:\ProgramFiles\JetBrains\IntelliJ IDEA 2017.2\bin” -Dfile.encoding=UTF-8 -classpath D:\Java\jdk1.8.0_131\jre\lib\charsets.jar;D:\Java\jdk1.8.0_131\jre\lib\deploy.jar;D:\Java\jdk1.8.0_131\jre\lib\ext\access-bridge-64.jar;D:\Java\jdk1.8.0_131\jre\lib\ext\cldrdata.jar;D:\Java\jdk1.8.0_131\jre\lib\ext\dnsns.jar;D:\Java\jdk1.8.0_131\jre\lib\ext\jaccess.jar;D:\Java\jdk1.8.0_131\jre\lib\ext\jfxrt.jar;D:\Java\jdk1.8.0_131\jre\lib\ext\localedata.jar;D:\Java\jdk1.8.0_131\jre\lib\ext\nashorn.jar;D:\Java\jdk1.8.0_131\jre\lib\ext\sunec.jar;D:\Java\jdk1.8.0_131\jre\lib\ext\sunjce_provider.jar;D:\Java\jdk1.8.0_131\jre\lib\ext\sunmscapi.jar;D:\Java\jdk1.8.0_131\jre\lib\ext\sunpkcs11.jar;D:\Java\jdk1.8.0_131\jre\lib\ext\zipfs.jar;D:\Java\jdk1.8.0_131\jre\lib\javaws.jar;D:\Java\jdk1.8.0_131\jre\lib\jce.jar;D:\Java\jdk1.8.0_131\jre\lib\jfr.jar;D:\Java\jdk1.8.0_131\jre\lib\jfxswt.jar;D:\Java\jdk1.8.0_131\jre\lib\jsse.jar;D:\Java\jdk1.8.0_131\jre\lib\management-agent.jar;D:\Java\jdk1.8.0_131\jre\lib\plugin.jar;D:\Java\jdk1.8.0_131\jre\lib\resources.jar;D:\Java\jdk1.8.0_131\jre\lib\rt.jar;F:\git-personal\luckmoney\target\classes;C:\Users\ZJAC-06.m2\repository\org\springframework\boot\spring-boot-starter-web\2.1.3.RELEASE\spring-boot-starter-web-2.1.3.RELEASE.jar;C:\Users\ZJAC-06.m2\repository\org\springframework\boot\spring-boot-starter\2.1.3.RELEASE\spring-boot-starter-2.1.3.RELEASE.jar;C:\Users\ZJAC-06.m2\repository\org\springframework\boot\spring-boot\2.1.3.RELEASE\spring-boot-2.1.3.RELEASE.jar;C:\Users\ZJAC-06.m2\repository\org\springframework\boot\spring-boot-autoconfigure\2.1.3.RELEASE\spring-boot-autoconfigure-2.1.3.RELEASE.jar;C:\Users\ZJAC-06.m2\repository\org\springframework\boot\spring-boot-starter-logging\2.1.3.RELEASE\spring-boot-starter-logging-2.1.3.RELEASE.jar;C:\Users\ZJAC-06.m2\repository\ch\qos\logback\logback-classic\1.2.3\logback-classic-1.2.3.jar;C:\Users\ZJAC-06.m2\repository\ch\qos\logback\logback-core\1.2.3\logback-core-1.2.3.jar;C:\Users\ZJAC-06.m2\repository\org\apache\logging\log4j\log4j-to-slf4j\2.11.2\log4j-to-slf4j-2.11.2.jar;C:\Users\ZJAC-06.m2\repository\org\apache\logging\log4j\log4j-api\2.11.2\log4j-api-2.11.2.jar;C:\Users\ZJAC-06.m2\repository\org\slf4j\jul-to-slf4j\1.7.25\jul-to-slf4j-1.7.25.jar;C:\Users\ZJAC-06.m2\repository\javax\annotation\javax.annotation-api\1.3.2\javax.annotation-api-1.3.2.jar;C:\Users\ZJAC-06.m2\repository\org\yaml\snakeyaml\1.23\snakeyaml-1.23.jar;C:\Users\ZJAC-06.m2\repository\org\springframework\boot\spring-boot-starter-json\2.1.3.RELEASE\spring-boot-starter-json-2.1.3.RELEASE.jar;C:\Users\ZJAC-06.m2\repository\com\fasterxml\jackson\core\jackson-databind\2.9.8\jackson-databind-2.9.8.jar;C:\Users\ZJAC-06.m2\repository\com\fasterxml\jackson\core\jackson-annotations\2.9.0\jackson-annotations-2.9.0.jar;C:\Users\ZJAC-06.m2\repository\com\fasterxml\jackson\core\jackson-core\2.9.8\jackson-core-2.9.8.jar;C:\Users\ZJAC-06.m2\repository\com\fasterxml\jackson\datatype\jackson-datatype-jdk8\2.9.8\jackson-datatype-jdk8-2.9.8.jar;C:\Users\ZJAC-06.m2\repository\com\fasterxml\jackson\datatype\jackson-datatype-jsr310\2.9.8\jackson-datatype-jsr310-2.9.8.jar;C:\Users\ZJAC-06.m2\repository\com\fasterxml\jackson\module\jackson-module-parameter-names\2.9.8\jackson-module-parameter-names-2.9.8.jar;C:\Users\ZJAC-06.m2\repository\org\springframework\boot\spring-boot-starter-tomcat\2.1.3.RELEASE\spring-boot-starter-tomcat-2.1.3.RELEASE.jar;C:\Users\ZJAC-06.m2\repository\org\apache\tomcat\embed\tomcat-embed-core\9.0.16\tomcat-embed-core-9.0.16.jar;C:\Users\ZJAC-06.m2\repository\org\apache\tomcat\embed\tomcat-embed-el\9.0.16\tomcat-embed-el-9.0.16.jar;C:\Users\ZJAC-06.m2\repository\org\apache\tomcat\embed\tomcat-embed-websocket\9.0.16\tomcat-embed-websocket-9.0.16.jar;C:\Users\ZJAC-06.m2\repository\org\hibernate\validator\hibernate-validator\6.0.14.Final\hibernate-validator-6.0.14.Final.jar;C:\Users\ZJAC-06.m2\repository\javax\validation\validation-api\2.0.1.Final\validation-api-2.0.1.Final.jar;C:\Users\ZJAC-06.m2\repository\org\jboss\logging\jboss-logging\3.3.2.Final\jboss-logging-3.3.2.Final.jar;C:\Users\ZJAC-06.m2\repository\com\fasterxml\classmate\1.4.0\classmate-1.4.0.jar;C:\Users\ZJAC-06.m2\repository\org\springframework\spring-web\5.1.5.RELEASE\spring-web-5.1.5.RELEASE.jar;C:\Users\ZJAC-06.m2\repository\org\springframework\spring-beans\5.1.5.RELEASE\spring-beans-5.1.5.RELEASE.jar;C:\Users\ZJAC-06.m2\repository\org\springframework\spring-webmvc\5.1.5.RELEASE\spring-webmvc-5.1.5.RELEASE.jar;C:\Users\ZJAC-06.m2\repository\org\springframework\spring-aop\5.1.5.RELEASE\spring-aop-5.1.5.RELEASE.jar;C:\Users\ZJAC-06.m2\repository\org\springframework\spring-context\5.1.5.RELEASE\spring-context-5.1.5.RELEASE.jar;C:\Users\ZJAC-06.m2\repository\org\springframework\spring-expression\5.1.5.RELEASE\spring-expression-5.1.5.RELEASE.jar;C:\Users\ZJAC-06.m2\repository\org\slf4j\slf4j-api\1.7.25\slf4j-api-1.7.25.jar;C:\Users\ZJAC-06.m2\repository\net\bytebuddy\byte-buddy\1.9.10\byte-buddy-1.9.10.jar;C:\Users\ZJAC-06.m2\repository\org\springframework\spring-core\5.1.5.RELEASE\spring-core-5.1.5.RELEASE.jar;C:\Users\ZJAC-06.m2\repository\org\springframework\spring-jcl\5.1.5.RELEASE\spring-jcl-5.1.5.RELEASE.jar;C:\Users\ZJAC-06.m2\repository\org\springframework\boot\spring-boot-starter-data-jpa\2.1.3.RELEASE\spring-boot-starter-data-jpa-2.1.3.RELEASE.jar;C:\Users\ZJAC-06.m2\repository\org\springframework\boot\spring-boot-starter-aop\2.1.3.RELEASE\spring-boot-starter-aop-2.1.3.RELEASE.jar;C:\Users\ZJAC-06.m2\repository\org\aspectj\aspectjweaver\1.9.2\aspectjweaver-1.9.2.jar;C:\Users\ZJAC-06.m2\repository\org\springframework\boot\spring-boot-starter-jdbc\2.1.3.RELEASE\spring-boot-starter-jdbc-2.1.3.RELEASE.jar;C:\Users\ZJAC-06.m2\repository\com\zaxxer\HikariCP\3.2.0\HikariCP-3.2.0.jar;C:\Users\ZJAC-06.m2\repository\org\springframework\spring-jdbc\5.1.5.RELEASE\spring-jdbc-5.1.5.RELEASE.jar;C:\Users\ZJAC-06.m2\repository\javax\transaction\javax.transaction-api\1.3\javax.transaction-api-1.3.jar;C:\Users\ZJAC-06.m2\repository\javax\xml\bind\jaxb-api\2.3.1\jaxb-api-2.3.1.jar;C:\Users\ZJAC-06.m2\repository\javax\activation\javax.activation-api\1.2.0\javax.activation-api-1.2.0.jar;C:\Users\ZJAC-06.m2\repository\org\hibernate\hibernate-core\5.3.7.Final\hibernate-core-5.3.7.Final.jar;C:\Users\ZJAC-06.m2\repository\javax\persistence\javax.persistence-api\2.2\javax.persistence-api-2.2.jar;C:\Users\ZJAC-06.m2\repository\org\javassist\javassist\3.23.1-GA\javassist-3.23.1-GA.jar;C:\Users\ZJAC-06.m2\repository\antlr\antlr\2.7.7\antlr-2.7.7.jar;C:\Users\ZJAC-06.m2\repository\org\jboss\jandex\2.0.5.Final\jandex-2.0.5.Final.jar;C:\Users\ZJAC-06.m2\repository\org\dom4j\dom4j\2.1.1\dom4j-2.1.1.jar;C:\Users\ZJAC-06.m2\repository\org\hibernate\common\hibernate-commons-annotations\5.0.4.Final\hibernate-commons-annotations-5.0.4.Final.jar;C:\Users\ZJAC-06.m2\repository\org\springframework\data\spring-data-jpa\2.1.5.RELEASE\spring-data-jpa-2.1.5.RELEASE.jar;C:\Users\ZJAC-06.m2\repository\org\springframework\data\spring-data-commons\2.1.5.RELEASE\spring-data-commons-2.1.5.RELEASE.jar;C:\Users\ZJAC-06.m2\repository\org\springframework\spring-orm\5.1.5.RELEASE\spring-orm-5.1.5.RELEASE.jar;C:\Users\ZJAC-06.m2\repository\org\springframework\spring-tx\5.1.5.RELEASE\spring-tx-5.1.5.RELEASE.jar;C:\Users\ZJAC-06.m2\repository\org\springframework\spring-aspects\5.1.5.RELEASE\spring-aspects-5.1.5.RELEASE.jar;C:\Users\ZJAC-06.m2\repository\mysql\mysql-connector-java\8.0.15\mysql-connector-java-8.0.15.jar com.imooc.luckmoney.LuckmoneyApplication
. ____ _ __ _ _
/\ / ’ __ _ () __ __ _ \ \ \
( ( )__ | '_ | '| | ’ / ` | \ \ \
\/ )| |)| | | | | || (| | ) ) ) )
’ || .__|| ||| |__, | / / / /
=|_|======|/=////
:: Spring Boot :: (v2.1.3.RELEASE)
2019-04-18 14:59:01.579 INFO 12168 — [ main] c.imooc.luckmoney.LuckmoneyApplication : Starting LuckmoneyApplication on DESKTOP-8305DO7 with PID 12168 (F:\git-personal\luckmoney\target\classes started by ZJAC-06 in F:\git-personal\luckmoney)
2019-04-18 14:59:01.583 INFO 12168 — [ main] c.imooc.luckmoney.LuckmoneyApplication : The following profiles are active: dev
2019-04-18 14:59:02.498 INFO 12168 — [ main] .s.d.r.c.RepositoryConfigurationDelegate : Bootstrapping Spring Data repositories in DEFAULT mode.
2019-04-18 14:59:02.540 INFO 12168 — [ main] .s.d.r.c.RepositoryConfigurationDelegate : Finished Spring Data repository scanning in 37ms. Found 1 repository interfaces.
2019-04-18 14:59:02.774 INFO 12168 — [ main] trationDelegateBeanPostProcessorChecker:Bean′org.springframework.transaction.annotation.ProxyTransactionManagementConfiguration′oftype[org.springframework.transaction.annotation.ProxyTransactionManagementConfigurationBeanPostProcessorChecker : Bean 'org.springframework.transaction.annotation.ProxyTransactionManagementConfiguration' of type [org.springframework.transaction.annotation.ProxyTransactionManagementConfigurationBeanPostProcessorChecker:Bean′org.springframework.transaction.annotation.ProxyTransactionManagementConfiguration′oftype[org.springframework.transaction.annotation.ProxyTransactionManagementConfigurationEnhancerBySpringCGLIBEnhancerBySpringCGLIBEnhancerBySpringCGLIBKaTeX parse error: Expected 'EOF', got '\Java' at position 790: …brary.path: [D:\̲J̲a̲v̲a̲\jdk1.8.0_131\b…JpaWebMvcConfiguration : spring.jpa.open-in-view is enabled by default. Therefore, database queries may be performed during view rendering. Explicitly configure spring.jpa.open-in-view to disable this warning
2019-04-18 14:59:04.591 WARN 12168 — [ main] ConfigServletWebServerApplicationContext : Exception encountered during context initialization - cancelling refresh attempt: org.springframework.beans.factory.BeanCreationException: Error creating bean with name ‘requestMappingHandlerMapping’ defined in class path resource [org/springframework/boot/autoconfigure/web/servlet/WebMvcAutoConfiguration$EnableWebMvcConfiguration.class]: Invocation of init method failed; nested exception is java.lang.IllegalStateException: Ambiguous mapping. Cannot map ‘luckmoneyController’ method
public java.util.List<com.imooc.luckmoney.Luckmoney> com.imooc.luckmoney.LuckmoneyController.list()
to {GET /luckmoneys}: There is already ‘luckmoneyController’ bean method
public com.imooc.luckmoney.Luckmoney com.imooc.luckmoney.LuckmoneyController.create(java.lang.String,java.math.BigDecimal) mapped.
2019-04-18 14:59:04.591 INFO 12168 — [ main] o.s.s.concurrent.ThreadPoolTaskExecutor : Shutting down ExecutorService 'applicationTaskExecutor’
2019-04-18 14:59:04.592 INFO 12168 — [ main] j.LocalContainerEntityManagerFactoryBean : Closing JPA EntityManagerFactory for persistence unit 'default’
2019-04-18 14:59:04.593 INFO 12168 — [ main] com.zaxxer.hikari.HikariDataSource : HikariPool-1 - Shutdown initiated…
2019-04-18 14:59:04.596 INFO 12168 — [ main] com.zaxxer.hikari.HikariDataSource : HikariPool-1 - Shutdown completed.
2019-04-18 14:59:04.597 INFO 12168 — [ main] o.apache.catalina.core.StandardService : Stopping service [Tomcat]
2019-04-18 14:59:04.604 INFO 12168 — [ main] ConditionEvaluationReportLoggingListener :
Error starting ApplicationContext. To display the conditions report re-run your application with ‘debug’ enabled.
2019-04-18 14:59:04.611 ERROR 12168 — [ main] o.s.boot.SpringApplication : Application run failed
org.springframework.beans.factory.BeanCreationException: Error creating bean with name ‘requestMappingHandlerMapping’ defined in class path resource [org/springframework/boot/autoconfigure/web/servlet/WebMvcAutoConfigurationEnableWebMvcConfiguration.class]:Invocationofinitmethodfailed;nestedexceptionisjava.lang.IllegalStateException:Ambiguousmapping.Cannotmap′luckmoneyController′methodpublicjava.util.List<com.imooc.luckmoney.Luckmoney>com.imooc.luckmoney.LuckmoneyController.list()toGET/luckmoneys:∗∗Thereisalready′luckmoneyController′beanmethod∗∗publiccom.imooc.luckmoney.Luckmoneycom.imooc.luckmoney.LuckmoneyController.create(java.lang.String,java.math.BigDecimal)mapped.atorg.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1762) [spring−beans−5.1.5.RELEASE.jar:5.1.5.RELEASE]atorg.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:593) [spring−beans−5.1.5.RELEASE.jar:5.1.5.RELEASE]atorg.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:515) [spring−beans−5.1.5.RELEASE.jar:5.1.5.RELEASE]atorg.springframework.beans.factory.support.AbstractBeanFactory.lambdaEnableWebMvcConfiguration.class]: Invocation of init method failed; nested exception is java.lang.IllegalStateException: Ambiguous mapping. Cannot map 'luckmoneyController' method
public java.util.List<com.imooc.luckmoney.Luckmoney> com.imooc.luckmoney.LuckmoneyController.list()
to {GET /luckmoneys}: **There is already 'luckmoneyController' bean method**
public com.imooc.luckmoney.Luckmoney com.imooc.luckmoney.LuckmoneyController.create(java.lang.String,java.math.BigDecimal) mapped.
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1762) ~[spring-beans-5.1.5.RELEASE.jar:5.1.5.RELEASE]
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:593) ~[spring-beans-5.1.5.RELEASE.jar:5.1.5.RELEASE]
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:515) ~[spring-beans-5.1.5.RELEASE.jar:5.1.5.RELEASE]
at org.springframework.beans.factory.support.AbstractBeanFactory.lambdaEnableWebMvcConfiguration.class]:Invocationofinitmethodfailed;nestedexceptionisjava.lang.IllegalStateException:Ambiguousmapping.Cannotmap′luckmoneyController′methodpublicjava.util.List<com.imooc.luckmoney.Luckmoney>com.imooc.luckmoney.LuckmoneyController.list()toGET/luckmoneys:∗∗Thereisalready′luckmoneyController′beanmethod∗∗publiccom.imooc.luckmoney.Luckmoneycom.imooc.luckmoney.LuckmoneyController.create(java.lang.String,java.math.BigDecimal)mapped.atorg.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1762) [spring−beans−5.1.5.RELEASE.jar:5.1.5.RELEASE]atorg.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:593) [spring−beans−5.1.5.RELEASE.jar:5.1.5.RELEASE]atorg.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:515) [spring−beans−5.1.5.RELEASE.jar:5.1.5.RELEASE]atorg.springframework.beans.factory.support.AbstractBeanFactory.lambdadoGetBean$0(AbstractBeanFactory.java:320) ~[spring-beans-5.1.5.RELEASE.jar:5.1.5.RELEASE]
at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:222) ~[spring-beans-5.1.5.RELEASE.jar:5.1.5.RELEASE]
at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:318) ~[spring-beans-5.1.5.RELEASE.jar:5.1.5.RELEASE]
at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:199) ~[spring-beans-5.1.5.RELEASE.jar:5.1.5.RELEASE]
at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:849) ~[spring-beans-5.1.5.RELEASE.jar:5.1.5.RELEASE]
at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:877) ~[spring-context-5.1.5.RELEASE.jar:5.1.5.RELEASE]
at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:549) ~[spring-context-5.1.5.RELEASE.jar:5.1.5.RELEASE]
at
at com.imooc.luckmoney.LuckmoneyApplication.main(LuckmoneyApplication.java:17) [classes/:na]
Caused by: java.lang.IllegalStateException: Ambiguous mapping. Cannot map ‘luckmoneyController’ method
public java.util.List<com.imooc.luckmoney.Luckmoney> com.imooc.luckmoney.LuckmoneyController.list()
to {GET /luckmoneys}: There is already ‘luckmoneyController’ bean method
public com.imooc.luckmoney.Luckmoney com.imooc.luckmoney.LuckmoneyController.create(java.lang.String,java.math.BigDecimal) mapped.
… 16 common frames omitted
Process finished with exit code 1
1回答
-
获取红包@GetMapping("/luckymoneys")
创建红包@PostMapping("luckymoney")
查询Id红包@GetMapping("/luckymoneys/{id}")
更新红包@PutMapping("/luckymoneys/{id}")
我也是新人,这个问题不大,你可以自己好好研究,都是看错的问题
122019-04-22
相似问题
回答 2