網(wǎng)站續(xù)費怎么做分錄百度搜一下
1 介紹
一年多前,我就買了好多關(guān)于Java開發(fā)類的書籍,內(nèi)容關(guān)于Java Web實操、Spring 學(xué)習(xí)指南、Maven實戰(zhàn)、IntelliJ IDEA軟件開發(fā)與應(yīng)用等等??墒怯捎诠ぷ鞣泵?#xff0c;這些書沒系統(tǒng)地看完。這也是參加工作后的無奈吧!
寒假期間的一周(從2024年1月22日–26日),參加了學(xué)校組織的一個免費的Java架構(gòu)師培訓(xùn)。培訓(xùn)的內(nèi)容包括傳統(tǒng)Java Web開發(fā)、各種框架的介紹、SSM 項目開發(fā)、Spring Boot項目開發(fā)、微服務(wù)等,很豐富。自己對這些內(nèi)容很感興趣,也愿意學(xué),無奈當(dāng)時工作忙,臨近期末批改期末大報告的關(guān)鍵期,沒認真聽。只好現(xiàn)在重現(xiàn)復(fù)盤、學(xué)習(xí)培訓(xùn)的內(nèi)容。
2 問題表現(xiàn)及解決方法
其中有一個SSM Java Web項目,我完全按照培訓(xùn)師給出的代碼,無法得到正確網(wǎng)頁展現(xiàn)。從事后回顧來說,涉及到項目的spring-mvc.xml
文件。具體描述如下。
代碼文件TeacherController.java
用于指定要訪問的網(wǎng)址“/teacher/list”,從而能讓網(wǎng)頁返回一個從MySQL數(shù)據(jù)庫中讀取的teacher表信息,其代碼如下:
package org.example.controller;import org.example.pojo.Teacher;
import org.example.service.TeacherService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;import java.util.List;@RestController
@RequestMapping("/teacher")
public class TeacherController {@Autowiredprivate TeacherService teacherService;/*** 請求地址:/teacher/list* @return 老師列表*/@RequestMapping("/list")public List<Teacher> getTeacherList(){List<Teacher> teacherList = teacherService.getTeacherList();return teacherList;}
}
配置文件spring-mvc.xml
的內(nèi)容如下:
<?xml version="1.0" encoding="UTF-8" ?>
<beans xmlns="http://www.springframework.org/schema/beans"xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"xmlns:context="http://www.springframework.org/schema/context"xmlns:mvc="http://www.springframework.org/schema/mvc"xmlns:tx="http://www.springframework.org/schema/tx"xsi:schemaLocation="http://www.springframework.org/schema/beanshttp://www.springframework.org/schema/beans/spring-beans.xsdhttp://www.springframework.org/schema/contexthttps://www.springframework.org/schema/contex/spring-context.xsdhttp://www.springframework.org/schema/mvchttps://www.springframework.org/schema/mvc/spring-mvc.xsdhttp://www.springframework.org/schema/txhttp://www.springframework.org/schema/tx/spring-tx.xsd"><!--組件掃描--><context:component-scan base-package="org.example.*" /><!--注解驅(qū)動,能夠進行消息轉(zhuǎn)換,返回JSON數(shù)據(jù)--><mvc:annotation-driven><mvc:message-converters><bean class="com.alibaba.fastjson.support.spring.FastJsonHttpMessageConverter"><property name="defaultCharset" value="utf-8" /><property name="supportedMediaTypes"><list><value>text/html;charset=UTF-8</value><value>application/json</value></list></property></bean></mvc:message-converters></mvc:annotation-driven><!--事文件解析器--><bean id="multipartResolver" class="org.springframework.web.multipart.commons.CommonsMultipartResolver"><property name="defaultEncoding" value="UTF-8" /></bean><!--事務(wù)管理器--><bean id="transactionManager" class="org.springframework.jdbc.datasource.DataSourceTransactionManager"><property name="dataSource" ref="dataSource" /></bean><!--事務(wù)注解驅(qū)動器--><tx:annotation-driven/><!--mvc默認處理器 --><mvc:default-servlet-handler />
</beans>
其中,從事后的角度講,上述配置文件出問題的是如下的xsi:schemaLocation內(nèi)容:
xsi:schemaLocation="http://www.springframework.org/schema/beanshttp://www.springframework.org/schema/beans/spring-beans.xsdhttp://www.springframework.org/schema/contexthttps://www.springframework.org/schema/contex/spring-context.xsdhttp://www.springframework.org/schema/mvchttps://www.springframework.org/schema/mvc/spring-mvc.xsdhttp://www.springframework.org/schema/txhttp://www.springframework.org/schema/tx/spring-tx.xsd"
2.1 問題表現(xiàn)1及解決
問題表現(xiàn)1
按照上面配置,運行項目(在IDEA中點擊啟動Tomcat服務(wù)器的按鈕),能運行,且自動彈出了頁面,如下:
但當(dāng)我訪問 http://localhost:8080/teacher/list 時,出現(xiàn)如下圖:
讀取不到MySQL中的teacher表信息。
上面頁面提示信息與Tomcat server的執(zhí)行日志信息是一樣的,核心問題為:
14-Mar-2024 11:04:00.528 警告 [RMI TCP Connection(2)-127.0.0.1] org.springframework.util.xml.SimpleSaxErrorHandler.warning Ignored XML validation warning
org.xml.sax.SAXParseException; lineNumber: 16; columnNumber: 60; schema_reference.4: 無法讀取方案文檔 ‘https://www.springframework.org/schema/contex/spring-context.xsd’, 原因為 1) 無法找到文檔; 2) 無法讀取文檔; 3) 文檔的根元素不是 xsd:schema。
…
14-Mar-2024 11:04:00.537 嚴重 [RMI TCP Connection(2)-127.0.0.1] org.springframework.web.servlet.FrameworkServlet.initServletBean Context initialization failed
org.springframework.beans.factory.xml.XmlBeanDefinitionStoreException: Line 16 in XML document from file [D:\RBprogramming\StudySSM\ssm_demo\target\web-ssm_demo\WEB-INF\classes\spring-mvc.xml] is invalid; nested exception is org.xml.sax.SAXParseException; lineNumber: 16; columnNumber: 60; cvc-complex-type.2.4.c: 通配符的匹配很全面, 但無法找到元素 ‘context:component-scan’ 的聲明。
…
Caused by: org.xml.sax.SAXParseException; lineNumber: 16; columnNumber: 60; cvc-complex-type.2.4.c: 通配符的匹配很全面, 但無法找到元素 ‘context:component-scan’ 的聲明。
問題1解決
更改配置文件spring-mvc.xml
中的xsi:schemaLocation
的值為:
xsi:schemaLocation="http://www.springframework.org/schema/beanshttp://www.springframework.org/schema/beans/spring-beans-4.2.xsdhttp://www.springframework.org/schema/contexthttp://www.springframework.org/schema/context/spring-context-4.2.xsdhttp://www.springframework.org/schema/mvchttp://www.springframework.org/schema/mvc/spring-mvc-4.2.xsd"
亦即將spring-beans.xsd改為 spring-beans-4.2.xsd,spring-context.xsd改為spring-context-4.2.xsd,spring-mvc.xsd改為spring-mvc-4.2.xsd。
再次運行??梢园l(fā)現(xiàn),問題1的表現(xiàn)不再出現(xiàn)。但出現(xiàn)了新的問題。
2.2 問題表現(xiàn)2及解決
問題表現(xiàn)2
運行上面修改后的項目,仍會自動彈出"Hello World!"頁面,但訪問 http://localhost:8080/teacher/list 時,出現(xiàn)如下圖:
從Tomcat server的執(zhí)行日志信息中取出核心問題描述:
14-Mar-2024 12:02:58.706 嚴重 [RMI TCP Connection(2)-127.0.0.1] org.springframework.web.servlet.FrameworkServlet.initServletBean Context initialization failed
org.springframework.beans.factory.xml.XmlBeanDefinitionStoreException: Line 40 in XML document from file [D:\RBprogramming\StudySSM\ssm_demo\target\web-ssm_demo\WEB-INF\classes\spring-mvc.xml] is invalid; nested exception is org.xml.sax.SAXParseException; lineNumber: 40; columnNumber: 28; cvc-complex-type.2.4.c: 通配符的匹配很全面, 但無法找到元素 ‘tx:annotation-driven’ 的聲明。
at org.springframework.beans.factory.xml.XmlBeanDefinitionReader.doLoadBeanDefinitions(XmlBeanDefinitionReader.java:402)
…
Caused by: org.xml.sax.SAXParseException; lineNumber: 40; columnNumber: 28; cvc-complex-type.2.4.c: 通配符的匹配很全面, 但無法找到元素 ‘tx:annotation-driven’ 的聲明。
at com.sun.org.apache.xerces.internal.util.ErrorH
問題2解決
根據(jù)問題2的表述及與原始xsi:schemaLocation內(nèi)容的對比,我認為在xsi:schemaLocation的值中應(yīng)該追加如下內(nèi)容:
http://www.springframework.org/schema/tx
http://www.springframework.org/schema/tx/spring-tx.xsd
最終正確的完整的spring-mvc.xml文件為:
<?xml version="1.0" encoding="UTF-8" ?>
<beans xmlns="http://www.springframework.org/schema/beans"xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"xmlns:context="http://www.springframework.org/schema/context"xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd http://www.springframework.org/schema/context https://www.springframework.org/schema/context/spring-context.xsd"><!--讀取數(shù)據(jù)庫配置文件 --><context:property-placeholder location="classpath:jdbc.properties" /><!--數(shù)據(jù)源 --><bean id="dataSource" class="com.alibaba.druid.pool.DruidDataSource"><property name="driverClassName" value="${driverClassName}" /><property name="url" value="${url}" /><property name="username" value="${user}"/><property name="password" value="${pwd}" /></bean><!--SqlSession工廠對象 --><bean id="sqlSessionFactory" class="org.mybatis.spring.SqlSessionFactoryBean" ><property name="dataSource" ref="dataSource" /><property name="mapperLocations" value="classpath:mapper/*.xml" /><property name="plugins" ><array><bean class="com.github.pagehelper.PageInterceptor"></bean></array></property><property name="configuration"><bean class="org.apache.ibatis.session.Configuration" ><property name="mapUnderscoreToCamelCase" value="true" /></bean></property></bean><!--mapper包掃描器 --><bean class="org.mybatis.spring.mapper.MapperScannerConfigurer"><property name="basePackage" value="org.example.mapper" /></bean>
</beans>
運行后,會自動彈出“Hello World!”頁面,但是,再次訪問http://localhost:8080/teacher/list,服務(wù)器的執(zhí)行l(wèi)og中無限循環(huán)報錯。
2.3 問題表現(xiàn)3及解決
問題表現(xiàn)3
出現(xiàn)的問題核心描述為:
java.sql.SQLNonTransientConnectionException: Public Key Retrieval is not allowed
問題3解決
將jdbc的連接設(shè)為:
url=jdbc:mysql://localhost:3306/ssm_demo?useSSL=false&allowPublicKeyRetrieval=true
再次運行,訪問http://localhost:8080/teacher/list,得到:
能讀取到數(shù)據(jù)庫中的信息了。
3 結(jié)語
遇到問題,要敢于解決。培訓(xùn)老師留下了好多空白,需要自己課下摸索。因為培訓(xùn)和平時上課很不一樣。培訓(xùn)一般要求是在短時間內(nèi)講授大量的內(nèi)容。
所以參加培訓(xùn),課下加強編程實踐鍛煉很有必要。