https://blog.csdn.net/chengxu_hou/article/details/71747608
@Id
@GeneratedValue(strategy = GenerationType.AUTO)
@Column(name = "mid")
public int getMid() {
return mid;
}
或者
<id name="id" column="id">
<generator class="native">generator>
id>
session.save等类似的操作之后不要设置对象。
<allowed-methods>
login
allowed-methods>
?
) are no longer supported;use JPA-style ordinal parameters (e.g., `?1`) instead : from com.rensiyu.book.entity.UserEntity as u where u.userName= ? and u.userPasswd=? [from com.rensiyu.book.entity.UserEntity as u where u.userName= ? and u.userPasswd=?]
at org.hibernate.internal.ExceptionConverterImpl.convert(ExceptionConverterImpl.java:138)
at org.hibernate.internal.ExceptionConverterImpl.convert(ExceptionConverterImpl.java:181)
at org.hibernate.internal.ExceptionConverterImpl.convert(ExceptionConverterImpl.java:188)
at org.hibernate.internal.AbstractSharedSessionContract.createQuery(AbstractSharedSessionContract.java:713)
at org.hibernate.internal.AbstractSessionImpl.createQuery(AbstractSessionImpl.java:23)
at com.rensiyu.book.dao.UserDaoImpl.login(UserDaoImpl.java:30)
at com.rensiyu.book.service.UserServiceImpl.login(UserServiceImpl.java:25)
at com.rensiyu.book.service.UserServiceImpl$$FastClassBySpringCGLIB$$128767da.invoke(<generated>)
可以参考 https://www.cnblogs.com/King-boy/p/11545508.html
在项目中加上基于xml的aop后,项目无法启动,错误信息如下:
Error creating bean with name ‘customerService’ defined in class path resource [bean.xml]: BeanPostProcessor before instantiation of bean failed;
原因是少了一个jar包:aspectj.weaver.jar
<dependency>
<groupId>aspectjgroupId>
<artifactId>aspectjweaverartifactId>
<version>1.5.3version>
dependency>
pom.xml文件
<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.0modelVersion>
<groupId>com.rensiyu.secondbookgroupId>
<artifactId>ssh_bookartifactId>
<version>1.0-SNAPSHOTversion>
<packaging>warpackaging>
<name>ssh_book Maven Webappname>
<url>http://www.example.comurl>
<properties>
<project.build.sourceEncoding>UTF-8project.build.sourceEncoding>
<maven.compiler.source>1.8maven.compiler.source>
<maven.compiler.target>1.8maven.compiler.target>
<spring.version>5.1.3.RELEASEspring.version>
<struts2.version>2.5.18struts2.version>
<hibernate.version>5.4.0.Finalhibernate.version>
properties>
<dependencies>
<dependency>
<groupId>junitgroupId>
<artifactId>junitartifactId>
<version>4.11version>
<scope>testscope>
dependency>
<dependency>
<groupId>mysqlgroupId>
<artifactId>mysql-connector-javaartifactId>
<version>8.0.13version>
dependency>
<dependency>
<groupId>com.mchangegroupId>
<artifactId>c3p0artifactId>
<version>0.9.5.2version>
dependency>
<dependency>
<groupId>org.springframeworkgroupId>
<artifactId>spring-coreartifactId>
<version>${spring.version}version>
dependency>
<dependency>
<groupId>org.springframeworkgroupId>
<artifactId>spring-contextartifactId>
<version>${spring.version}version>
dependency>
<dependency>
<groupId>org.springframeworkgroupId>
<artifactId>spring-beansartifactId>
<version>${spring.version}version>
dependency>
<dependency>
<groupId>org.springframeworkgroupId>
<artifactId>spring-expressionartifactId>
<version>${spring.version}version>
dependency>
<dependency>
<groupId>org.springframeworkgroupId>
<artifactId>spring-ormartifactId>
<version>${spring.version}version>
dependency>
<dependency>
<groupId>org.springframeworkgroupId>
<artifactId>spring-jdbcartifactId>
<version>${spring.version}version>
dependency>
<dependency>
<groupId>org.springframeworkgroupId>
<artifactId>spring-txartifactId>
<version>${spring.version}version>
dependency>
<dependency>
<groupId>org.springframeworkgroupId>
<artifactId>spring-webartifactId>
<version>${spring.version}version>
dependency>
<dependency>
<groupId>org.springframeworkgroupId>
<artifactId>spring-aopartifactId>
<version>${spring.version}version>
dependency>
<dependency>
<groupId>org.apache.strutsgroupId>
<artifactId>struts2-coreartifactId>
<version>${struts2.version}version>
dependency>
<dependency>
<groupId>org.apache.strutsgroupId>
<artifactId>struts2-json-pluginartifactId>
<version>${struts2.version}version>
dependency>
<dependency>
<groupId>org.apache.strutsgroupId>
<artifactId>struts2-junit-pluginartifactId>
<version>${struts2.version}version>
<scope>testscope>
dependency>
<dependency>
<groupId>org.apache.strutsgroupId>
<artifactId>struts2-spring-pluginartifactId>
<version>${struts2.version}version>
dependency>
<dependency>
<groupId>javax.servletgroupId>
<artifactId>javax.servlet-apiartifactId>
<version>4.0.1version>
<scope>providedscope>
dependency>
<dependency>
<groupId>org.hibernategroupId>
<artifactId>hibernate-coreartifactId>
<version>${hibernate.version}version>
dependency>
dependencies>
<build>
<finalName>ssh_bookfinalName>
<pluginManagement>
<plugins>
<plugin>
<artifactId>maven-clean-pluginartifactId>
<version>3.1.0version>
plugin>
<plugin>
<artifactId>maven-resources-pluginartifactId>
<version>3.0.2version>
plugin>
<plugin>
<artifactId>maven-compiler-pluginartifactId>
<version>3.8.0version>
plugin>
<plugin>
<artifactId>maven-surefire-pluginartifactId>
<version>2.22.1version>
plugin>
<plugin>
<artifactId>maven-war-pluginartifactId>
<version>3.2.2version>
plugin>
<plugin>
<artifactId>maven-install-pluginartifactId>
<version>2.5.2version>
plugin>
<plugin>
<artifactId>maven-deploy-pluginartifactId>
<version>2.8.2version>
plugin>
plugins>
pluginManagement>
build>
project>
web.xml中classpath:和classpath*: 有什么区别?
classpath:只会到你的class路径中查找找文件;
classpath*:不仅包含class路径,还包括jar文件中(class路径)进行查找.
存放位置:
1:src下面
需要在web.xml中定义如下:
<context-param>
<param-name>contextConfigLocationparam-name>
<param-value>classpath:applicationContext.xmlparam-value>
context-param>
2:WEB-INF下面
需要在web.xml中定义如下:
<context-param>
<param-name>contextConfigLocationparam-name>
<param-value>WEB-INF/applicationContext*.xmlparam-value>
context-param>
web.xml 通过contextConfigLocation配置spring 的方式
SSI框架配置文件路径问题:
struts2的 1个+N个 路径:src+src(可配置) 名称: struts.xml + N
spring 的 1个 路径: src 名称: applicationContext.xml
ibatis 的 1个+N个 路径: src+src(可配置) 名称: SqlMapConfig.xml + N
部署到tomcat后,src目录下的配置文件会和class文件一样,自动copy到应用的 classes目录下
spring的 配置文件在启动时,加载的是web-info目录下的applicationContext.xml,
运行时使用的是web-info/classes目录下的applicationContext.xml。
配置web.xml使这2个路径一致:
<context-param>
<param-name>contextConfigLocationparam-name>
<param-value>/WEB-INF/classes/applicationContext.xmlparam-value>
context-param>
多个配置文件的加载
<context-param>
<param-name>contextConfigLocationparam-name>
<param-value>
classpath*:conf/spring/applicationContext_core*.xml,
classpath*:conf/spring/applicationContext_dict*.xml,
classpath*:conf/spring/applicationContext_hibernate.xml,
classpath*:conf/spring/applicationContext_staff*.xml,
classpath*:conf/spring/applicationContext_security.xml
classpath*:conf/spring/applicationContext_modules*.xml
classpath*:conf/spring/applicationContext_cti*.xml
classpath*:conf/spring/applicationContext_apm*.xml
param-value>
context-param>
contextConfigLocation 参数定义了要装入的 Spring 配置文件。
首先与Spring相关的配置文件必须要以"applicationContext-"开头,要符合约定优于配置的思想,这样在效率上和出错率上都要好很多。
还有最好把所有Spring配置文件都放在一个统一的目录下,如果项目大了还可以在该目录下分模块建目录。这样程序看起来不会很乱。
在web.xml中的配置如下:
Xml代码
<context-param>
< param-name>contextConfigLocationparam-name>
< param-value>classpath*:**/applicationContext-*.xmlparam-value>
context-param>
"**/"表示的是任意目录;
"**/applicationContext-*.xml"表示任意目录下的以"applicationContext-"开头的XML文件。
你自己可以根据需要修改。最好把所有Spring配置文件都放在一个统一的目录下,如:
<context-param>
<param-name>contextConfigLocationparam-name>
<param-value>classpath:/spring/applicationContext-*.xmlparam-value>
context-param>
D:\Tools\apache-tomcat-9.0.24\bin\catalina.bat run
[2019-12-15 03:41:34,778] Artifact ssh_book:war exploded: Waiting for server connection to start artifact deployment...
Using CATALINA_BASE: "C:\Users\76147\.IntelliJIdea2019.1\system\tomcat\Unnamed_ssh_book"
Using CATALINA_HOME: "D:\Tools\apache-tomcat-9.0.24"
Using CATALINA_TMPDIR: "D:\Tools\apache-tomcat-9.0.24\temp"
Using JRE_HOME: "D:\Java\jdk1.8.0_211"
Using CLASSPATH: "D:\Tools\apache-tomcat-9.0.24\bin\bootstrap.jar;D:\Tools\apache-tomcat-9.0.24\bin\tomcat-juli.jar"
15-Dec-2019 15:41:35.986 信息 [main] org.apache.catalina.startup.VersionLoggerListener.log Server.服务器版本: Apache Tomcat/9.0.24
15-Dec-2019 15:41:35.988 信息 [main] org.apache.catalina.startup.VersionLoggerListener.log Server.构建: Aug 14 2019 21:16:42 UTC
15-Dec-2019 15:41:35.988 信息 [main] org.apache.catalina.startup.VersionLoggerListener.log Server version number: 9.0.24.0
15-Dec-2019 15:41:35.988 信息 [main] org.apache.catalina.startup.VersionLoggerListener.log OS Name: Windows 10
15-Dec-2019 15:41:35.989 信息 [main] org.apache.catalina.startup.VersionLoggerListener.log OS.版本: 10.0
15-Dec-2019 15:41:35.989 信息 [main] org.apache.catalina.startup.VersionLoggerListener.log 结.造: amd64
15-Dec-2019 15:41:35.989 信息 [main] org.apache.catalina.startup.VersionLoggerListener.log Java 环境变量: D:\Java\jdk1.8.0_211\jre
15-Dec-2019 15:41:35.989 信息 [main] org.apache.catalina.startup.VersionLoggerListener.log JVM 版本: 1.8.0_211-b12
15-Dec-2019 15:41:35.989 信息 [main] org.apache.catalina.startup.VersionLoggerListener.log JVM.供应商: Oracle Corporation
15-Dec-2019 15:41:35.989 信息 [main] org.apache.catalina.startup.VersionLoggerListener.log CATALINA_BASE: C:\Users\76147\.IntelliJIdea2019.1\system\tomcat\Unnamed_ssh_book
15-Dec-2019 15:41:35.989 信息 [main] org.apache.catalina.startup.VersionLoggerListener.log CATALINA_HOME: D:\Tools\apache-tomcat-9.0.24
15-Dec-2019 15:41:35.989 信息 [main] org.apache.catalina.startup.VersionLoggerListener.log Command line argument: -Djava.util.logging.config.file=C:\Users\76147\.IntelliJIdea2019.1\system\tomcat\Unnamed_ssh_book\conf\logging.properties
15-Dec-2019 15:41:35.989 信息 [main] org.apache.catalina.startup.VersionLoggerListener.log Command line argument: -Djava.util.logging.manager=org.apache.juli.ClassLoaderLogManager
15-Dec-2019 15:41:35.989 信息 [main] org.apache.catalina.startup.VersionLoggerListener.log Command line argument: -Dcom.sun.management.jmxremote=
15-Dec-2019 15:41:35.989 信息 [main] org.apache.catalina.startup.VersionLoggerListener.log Command line argument: -Dcom.sun.management.jmxremote.port=1099
15-Dec-2019 15:41:35.990 信息 [main] org.apache.catalina.startup.VersionLoggerListener.log Command line argument: -Dcom.sun.management.jmxremote.ssl=false
15-Dec-2019 15:41:35.990 信息 [main] org.apache.catalina.startup.VersionLoggerListener.log Command line argument: -Dcom.sun.management.jmxremote.password.file=C:\Users\76147\.IntelliJIdea2019.1\system\tomcat\Unnamed_ssh_book\jmxremote.password
15-Dec-2019 15:41:35.990 信息 [main] org.apache.catalina.startup.VersionLoggerListener.log Command line argument: -Dcom.sun.management.jmxremote.access.file=C:\Users\76147\.IntelliJIdea2019.1\system\tomcat\Unnamed_ssh_book\jmxremote.access
15-Dec-2019 15:41:35.990 信息 [main] org.apache.catalina.startup.VersionLoggerListener.log Command line argument: -Djava.rmi.server.hostname=127.0.0.1
15-Dec-2019 15:41:35.990 信息 [main] org.apache.catalina.startup.VersionLoggerListener.log Command line argument: -Djdk.tls.ephemeralDHKeySize=2048
15-Dec-2019 15:41:35.991 信息 [main] org.apache.catalina.startup.VersionLoggerListener.log Command line argument: -Djava.protocol.handler.pkgs=org.apache.catalina.webresources
15-Dec-2019 15:41:35.991 信息 [main] org.apache.catalina.startup.VersionLoggerListener.log Command line argument: -Dignore.endorsed.dirs=
15-Dec-2019 15:41:35.991 信息 [main] org.apache.catalina.startup.VersionLoggerListener.log Command line argument: -Dcatalina.base=C:\Users\76147\.IntelliJIdea2019.1\system\tomcat\Unnamed_ssh_book
15-Dec-2019 15:41:35.991 信息 [main] org.apache.catalina.startup.VersionLoggerListener.log Command line argument: -Dcatalina.home=D:\Tools\apache-tomcat-9.0.24
15-Dec-2019 15:41:35.991 信息 [main] org.apache.catalina.startup.VersionLoggerListener.log Command line argument: -Djava.io.tmpdir=D:\Tools\apache-tomcat-9.0.24\temp
15-Dec-2019 15:41:35.991 信息 [main] org.apache.catalina.core.AprLifecycleListener.lifecycleEvent Loaded APR based Apache Tomcat Native library [1.2.23] using APR version [1.7.0].
15-Dec-2019 15:41:35.992 信息 [main] org.apache.catalina.core.AprLifecycleListener.lifecycleEvent APR capabilities: IPv6 [true], sendfile [true], accept filters [false], random [true].
15-Dec-2019 15:41:35.992 信息 [main] org.apache.catalina.core.AprLifecycleListener.lifecycleEvent APR/OpenSSL configuration: useAprConnector [false], useOpenSSL [true]
15-Dec-2019 15:41:35.996 信息 [main] org.apache.catalina.core.AprLifecycleListener.initializeSSL OpenSSL successfully initialized [OpenSSL 1.1.1c 28 May 2019]
15-Dec-2019 15:41:36.175 信息 [main] org.apache.coyote.AbstractProtocol.init 初始化协议处理器 ["http-nio-8080"]
15-Dec-2019 15:41:36.195 信息 [main] org.apache.coyote.AbstractProtocol.init 初始化协议处理器 ["ajp-nio-8009"]
15-Dec-2019 15:41:36.197 信息 [main] org.apache.catalina.startup.Catalina.load 服务器在[431]毫秒内初始化
15-Dec-2019 15:41:36.220 信息 [main] org.apache.catalina.core.StandardService.startInternal Starting service [Catalina]
15-Dec-2019 15:41:36.220 信息 [main] org.apache.catalina.core.StandardEngine.startInternal Starting Servlet engine: [Apache Tomcat/9.0.24]
15-Dec-2019 15:41:36.230 信息 [main] org.apache.coyote.AbstractProtocol.start 开始协议处理句柄["http-nio-8080"]
15-Dec-2019 15:41:36.239 信息 [main] org.apache.coyote.AbstractProtocol.start 开始协议处理句柄["ajp-nio-8009"]
15-Dec-2019 15:41:36.241 信息 [main] org.apache.catalina.startup.Catalina.start Server startup in [44] milliseconds
[2019-12-15 03:41:36,439] Artifact ssh_book:war exploded: Artifact is being deployed, please wait...
Connected to server
15-Dec-2019 15:41:38.973 信息 [RMI TCP Connection(3)-127.0.0.1] org.apache.jasper.servlet.TldScanner.scanJars 至少有一个JAR被扫描用于TLD但尚未包含TLD。 为此记录器启用调试日志记录,以获取已扫描但未在其中找到TLD的完整JAR列表。 在扫描期间跳过不需要的JAR可以缩短启动时间和JSP编译时间。
ERROR StatusLogger Log4j2 could not find a logging implementation. Please add log4j-core to the classpath. Using SimpleLogger to log to the console...
15-Dec-2019 15:41:39.625 信息 [MLog-Init-Reporter] com.mchange.v2.log.MLog. MLog clients using java 1.4+ standard logging.
15-Dec-2019 15:41:39.669 信息 [RMI TCP Connection(3)-127.0.0.1] com.mchange.v2.c3p0.C3P0Registry. Initializing c3p0-0.9.5.2 [built 08-December-2015 22:06:04 -0800; debug? true; trace: 10]
15-Dec-2019 15:41:41.157 信息 [RMI TCP Connection(3)-127.0.0.1] com.mchange.v2.c3p0.impl.AbstractPoolBackedDataSource. Initializing c3p0 pool... com.mchange.v2.c3p0.ComboPooledDataSource [ acquireIncrement -> 3, acquireRetryAttempts -> 30, acquireRetryDelay -> 1000, autoCommitOnClose -> false, automaticTestTable -> null, breakAfterAcquireFailure -> false, checkoutTimeout -> 0, connectionCustomizerClassName -> null, connectionTesterClassName -> com.mchange.v2.c3p0.impl.DefaultConnectionTester, contextClassLoaderSource -> caller, dataSourceName -> 1hgf476a72cyll41u3pr89|5808eeca, debugUnreturnedConnectionStackTraces -> false, description -> null, driverClass -> com.mysql.jdbc.Driver, extensions -> {}, factoryClassLocation -> null, forceIgnoreUnresolvedTransactions -> false, forceSynchronousCheckins -> false, forceUseNamedDriverClass -> false, identityToken -> 1hgf476a72cyll41u3pr89|5808eeca, idleConnectionTestPeriod -> 0, initialPoolSize -> 3, jdbcUrl -> jdbc:mysql:///second_hand_book?serverTimezone=Asia/Shanghai, maxAdministrativeTaskTime -> 0, maxConnectionAge -> 0, maxIdleTime -> 0, maxIdleTimeExcessConnections -> 0, maxPoolSize -> 10, maxStatements -> 0, maxStatementsPerConnection -> 0, minPoolSize -> 5, numHelperThreads -> 3, preferredTestQuery -> null, privilegeSpawnedThreads -> false, properties -> {user=******, password=******}, propertyCycle -> 0, statementCacheNumDeferredCloseThreads -> 0, testConnectionOnCheckin -> false, testConnectionOnCheckout -> false, unreturnedConnectionTimeout -> 0, userOverrides -> {}, usesTraditionalReflectiveProxies -> false ]
15-Dec-2019 15:41:41.172 警告 [RMI TCP Connection(3)-127.0.0.1] com.mchange.v2.resourcepool.BasicResourcePool. Bad pool size config, start 3 < min 5. Using 5 as start.
Loading class `com.mysql.jdbc.Driver'. This is deprecated. The new driver class is `com.mysql.cj.jdbc.Driver'. The driver is automatically registered via the SPI and manual loading of the driver class is generally unnecessary.
[2019-12-15 03:41:43,482] Artifact ssh_book:war exploded: Artifact is deployed successfully
[2019-12-15 03:41:43,482] Artifact ssh_book:war exploded: Deploy took 7,043 milliseconds
15-Dec-2019 15:41:46.253 信息 [Catalina-utility-2] org.apache.catalina.startup.HostConfig.deployDirectory 把web 应用程序部署到目录 [D:\Tools\apache-tomcat-9.0.24\webapps\manager]
15-Dec-2019 15:41:46.431 信息 [Catalina-utility-2] org.apache.catalina.startup.HostConfig.deployDirectory Deployment of web application directory [D:\Tools\apache-tomcat-9.0.24\webapps\manager] has finished in [178] ms