第一个错误:org.hibernate.MappingException Unknown entity: com.entity.Admin在编写管理员注册的时候,老是报这个错,从网上百度了下,https://jingyan.baidu.com/article/e75aca8552761b142edac6cf.html,最后才发现是我的实体里面没有写注解。
第二个错误:org.hibernate.exception.GenericJDBCException: could not insert: [com.entity.Admin],
在改正前一个错误后,发现再次运行数据库里面的表已经建好了,但是又报出这个错误。这个问题一直百度,也找不到解决的方法,又因为我的使用注解来写的,没有实体配置文件所以一直找不到问题所在,但是,但是我继续找下面的报错:Caused by: java.sql.SQLException: Connection is read-only. Queries leading to data modification are not allowed
百度了一下这个错误:原来是我的配置文件里面写了只读:
<!-- 2、配置拦截规则
-->
<tx:advice id="txAdvice" transaction-manager="txManager">
<tx:attributes>
<tx:method name="get*" read-only="true" />
<tx:method name="find*" read-only="true" />
<tx:method name="load*" read-only="true" />
<tx:method name="add*" propagation="REQUIRED" />
<tx:method name="save*" propagation="REQUIRED" />
<tx:method name="update*" propagation="REQUIRED" />
<tx:method name="del*" propagation="REQUIRED" />
<tx:method name="*" propagation="REQUIRED" read-only="true" />
</tx:attributes>
</tx:advice>
把这一句去掉就好了
第三个错误:在我写到页面的时候,为了方便管理里面,我将每个功能的页面都打包了一个文件夹,
后来发现,页面的值老是取不到,还有的从之前复制过来的代码,发现图片都加载不了,
{
title :'操作',
field :'operation',
width : 100,
align : 'center',
formatter : function(value,row,index) {
return '<img src="image/edit.png" title="修改" style="cursor:pointer;" οnclick="sysAdmin_agentunit_editFun('+index+')"/> '+
'<img src="../image/del.png" title="删除" style="cursor:pointer;" οnclick="sysAdmin_agentunit_delFun('+row.id+')"/>';
}
}]],
之后在路径上返回上一层,加上../就好了。
第四个错误:报错 Ambiguous handler methods mapped for HTTP path '/admin/selectalladmin.action': {public void com.controller.AdminzcController.selectalladmin(javax.servlet.http.HttpServletRequest,javax.servlet.http.HttpServletResponse), public void com.controller.AdminzcController.deleteadmin(javax.servlet.http.HttpServletRequest,javax.servlet.http.HttpServletResponse,com.entity.Admin)}. If you intend to handle the same path in multiple methods, 后来百度了一下发现是两个注解名字写的一模一样。改正后就好了。
第五个错误:在之前写过admin的三层注解什么的都没问题,可是今天准备些people的时候,突然发现老是报错:
严重: Exception sending context initialized event to listener instance of class org.springframework.web.context.ContextLoaderListener
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'peopleController': Injection of autowired dependencies failed; nested exception is org.springframework.beans.factory.BeanCreationException: Could not autowire field: private com.service.PeopleService com.controller.PeopleController.ps; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'PeopleService': Injection of autowired dependencies failed; nested exception is org.springframework.beans.factory.BeanCreationException: Could not autowire field: private com.dao.PeopleDao com.service.imp.PeopleServiceImp.pd; nested exception is org.springframework.beans.factory.NoSuchBeanDefinitionException: No qualifying bean of type [com.dao.PeopleDao] found for dependency: expected at least 1 bean which qualifies as autowire candidate for this dependency. Dependency annotations: {@org.springframework.beans.factory.annotation.Autowired(required=true)}
at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor.postProcessPropertyValues(AutowiredAnnotationBeanPostProcessor.java:288)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean(AbstractAutowireCapableBeanFactory.java:1120)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:522)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:461)
at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:295)
at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:223)
at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:292)
at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:194)
at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:626)
at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:932)
at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:479)
at org.springframework.web.context.ContextLoader.configureAndRefreshWebApplicationContext(ContextLoader.java:389)
at org.springframework.web.context.ContextLoader.initWebApplicationContext(ContextLoader.java:294)
at org.springframework.web.context.ContextLoaderListener.contextInitialized(ContextLoaderListener.java:112)
at org.apache.catalina.core.StandardContext.listenerStart(StandardContext.java:5003)
at org.apache.catalina.core.StandardContext.startInternal(StandardContext.java:5517)
at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:150)
at org.apache.catalina.core.ContainerBase.addChildInternal(ContainerBase.java:901)
at org.apache.catalina.core.ContainerBase.addChild(ContainerBase.java:877)
at org.apache.catalina.core.StandardHost.addChild(StandardHost.java:652)
at org.apache.catalina.startup.HostConfig.deployDirectory(HostConfig.java:1263)
at org.apache.catalina.startup.HostConfig$DeployDirectory.run(HostConfig.java:1978)
at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:441)
at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:303)
at java.util.concurrent.FutureTask.run(FutureTask.java:138)
at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:886)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:908)
at java.lang.Thread.run(Thread.java:619)
Caused by: org.springframework.beans.factory.BeanCreationException: Could not autowire field: private com.service.PeopleService com.controller.PeopleController.ps; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'PeopleService': Injection of autowired dependencies failed; nested exception is org.springframework.beans.factory.BeanCreationException: Could not autowire field: private com.dao.PeopleDao com.service.imp.PeopleServiceImp.pd; nested exception is org.springframework.beans.factory.NoSuchBeanDefinitionException: No qualifying bean of type [com.dao.PeopleDao] found for dependency: expected at least 1 bean which qualifies as autowire candidate for this dependency. Dependency annotations: {@org.springframework.beans.factory.annotation.Autowired(required=true)}
at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor$AutowiredFieldElement.inject(AutowiredAnnotationBeanPostProcessor.java:514)
at org.springframework.beans.factory.annotation.InjectionMetadata.inject(InjectionMetadata.java:87)
at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor.postProcessPropertyValues(AutowiredAnnotationBeanPostProcessor.java:285)
... 27 more
Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'PeopleService': Injection of autowired dependencies failed; nested exception is org.springframework.beans.factory.BeanCreationException: Could not autowire field: private com.dao.PeopleDao com.service.imp.PeopleServiceImp.pd; nested exception is org.springframework.beans.factory.NoSuchBeanDefinitionException: No qualifying bean of type [com.dao.PeopleDao] found for dependency: expected at least 1 bean which qualifies as autowire candidate for this dependency. Dependency annotations: {@org.springframework.beans.factory.annotation.Autowired(required=true)}
at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor.postProcessPropertyValues(AutowiredAnnotationBeanPostProcessor.java:288)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean(AbstractAutowireCapableBeanFactory.java:1120)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:522)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:461)
at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:295)
at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:223)
at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:292)
at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:194)
at org.springframework.beans.factory.support.DefaultListableBeanFactory.findAutowireCandidates(DefaultListableBeanFactory.java:891)
at org.springframework.beans.factory.support.DefaultListableBeanFactory.doResolveDependency(DefaultListableBeanFactory.java:834)
at org.springframework.beans.factory.support.DefaultListableBeanFactory.resolveDependency(DefaultListableBeanFactory.java:749)
at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor$AutowiredFieldElement.inject(AutowiredAnnotationBeanPostProcessor.java:486)
... 29 more
Caused by: org.springframework.beans.factory.BeanCreationException: Could not autowire field: private com.dao.PeopleDao com.service.imp.PeopleServiceImp.pd; nested exception is org.springframework.beans.factory.NoSuchBeanDefinitionException: No qualifying bean of type [com.dao.PeopleDao] found for dependency: expected at least 1 bean which qualifies as autowire candidate for this dependency. Dependency annotations: {@org.springframework.beans.factory.annotation.Autowired(required=true)}
at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor$AutowiredFieldElement.inject(AutowiredAnnotationBeanPostProcessor.java:514)
at org.springframework.beans.factory.annotation.InjectionMetadata.inject(InjectionMetadata.java:87)
at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor.postProcessPropertyValues(AutowiredAnnotationBeanPostProcessor.java:285)
... 40 more
Caused by: org.springframework.beans.factory.NoSuchBeanDefinitionException: No qualifying bean of type [com.dao.PeopleDao] found for dependency: expected at least 1 bean which qualifies as autowire candidate for this dependency. Dependency annotations: {@org.springframework.beans.factory.annotation.Autowired(required=true)}
at org.springframework.beans.factory.support.DefaultListableBeanFactory.raiseNoSuchBeanDefinitionException(DefaultListableBeanFactory.java:967)
at org.springframework.beans.factory.support.DefaultListableBeanFactory.doResolveDependency(DefaultListableBeanFactory.java:837)
at org.springframework.beans.factory.support.DefaultListableBeanFactory.resolveDependency(DefaultListableBeanFactory.java:749)
at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor$AutowiredFieldElement.inject(AutowiredAnnotationBeanPostProcessor.java:486)
... 42 more
后来才发现我的配置文件springmvc-servlet.xml是这样写的
<!-- 注解 -->
<context:component-scan base-package="com.controller"/>
所以我在service层的实现层把@Autowired写到下面去了。
@Service("PeopleService")
public class PeopleServiceImp implements PeopleService{
private PeopleDao pd;
@Autowired
public PeopleDao getPd() {
return pd;
}
public void setPd(PeopleDao pd) {
this.pd = pd;
}
之后就可以了。
第六个错误:之前不曾理解注解到底怎么用,直到遇到了一个难以理解的空指针。首先我们在controller层的程序
@Controller
@RequestMapping("People")
public class PeopleController {
@Autowired
private PeopleService ps;
public PeopleService getPs() {
return ps;
}
public void setPs(PeopleService ps) {
this.ps = ps;
}
私有化了ps,所以在下一层:
@Service("ps")
public class PeopleServiceImp implements PeopleService{
private PeopleDao pd;
@Autowired
public PeopleDao getPd() {
return pd;
}
public void setPd(PeopleDao pd) {
this.pd = pd;
}
@Service里面的注解名字就要是我们起的变量名字。
再看Dao层:
@Repository("pd")
public class PeopleDaoImp implements PeopleDao {
@Autowired
private SessionFactory sessionFactory;
public Session openSession1() {
return sessionFactory.openSession();
}
public SessionFactory getSessionFactory() {
return sessionFactory;
}
public void setSessionFactory(SessionFactory sessionFactory) {
this.sessionFactory = sessionFactory;
}
public Session getCurrentSession() {
return sessionFactory.getCurrentSession();
}
同样是要私有化。这点之前一直不理解。谨记。