Maven Building SSM Projectについて簡単に説明しましょう(データベースOracleを使用することはMySQLよりももう少し面倒なので、こちらについて話しましょう)
Maven Webプロジェクトを作成するとき、メイン/Javaとメイン/テストの2つのフォルダーが欠けていることがよくあります。
解決:
①:プロジェクトを右クリックしてプロパティを選択し、[ライブラリの下のJavaビルドパス]をクリックし、JREシステムライブラリを編集し、WorkspaceのデフォルトJREを選択します。 (これが推奨されます)
②:ディレクトリを手動で作成します。スイッチビューはナビゲータービューを使用し、SRC/メインディレクトリにJavaディレクトリを直接作成します。
プロジェクトディレクトリ構造:
重要な構成ファイル:
オブジェクトモデル構成ファイル:pom.xml
Springの構成ファイル:ApplicationContext.xml
Spring MVC構成ファイル:SpringMVC.XML
データベース構成ファイル:jdbc.properties
ログ構成ファイル:log4j.Properties
mybatis構成ファイル:mybatis-config.xml
ネットワークプログラム構成ファイル:web.xml
最初にpom.xmlを構成します
POM.XMLは、主にプロジェクトのMaven座標、依存関係、JARパッケージを自動的に導入しています。
<Project XMLNS = "http://maven.apache.org/pom/4.0.0" xmlns:xsi = "http://www.w3.org/2001/xmlschema-instance" xsi:schemalocation = "http://maven.apach/4.0. http://maven.apache.org/maven-v4_0_0.xsd "> <modelversion> 4.0.0 </modelversion> <groupid> com.krry </groupid> <artifactid> maven_ssm </artifactid> <バージョン> 0.0.1-snapshot </version </version </varions < <url> http://maven.apache.org </url> <dependencies> <! - 紹介Junit-> <dependency> <groupid> junit </groupid> <artifactid> junit </artifactid> <バージョン> 4.11 </version> <scope> scope> < <groupid> javax.servlet </groupid> <artifactid> servlet-api </artifactid> <version> 3.0-alpha-1 </version> <scope> <scope> revide </scope> </dependency> <! - jspのコンピレーション依存関係の導入 - > <依存関係> <groupid> javax.servlet.jsp </groupid> <artifactid> jsp-api </artifactid> <バージョン> 2.2 </バージョン> <スコープ> <groupId> log4j </groupId> <artifactid> log4j </artifactid> <bersion> 1.2.17 </version> </dependency> <! - spring springmvc mybatis-> <! - spring and springmvc関連の構造JAR-> <依存関係> <依存関係> <グループdspringframework </artifid> <artifid> <artifactid> <artifactid> </groupid> <バージョン> 4.2.1.Release </version> </dependency> <dependency> <shipid> org.springframework </groupid> <artifactid> spring-jdbc </artifactid> <bersion> 4.2.1.Release </version> </dependency> <! - springmvc </depenty> <depenty> </relamed <artifactid> spring-webmvc </artifactid> <バージョン> 4.2.1.release </version> </dependency> <! - springmvcはjson変換パッケージジャクソン - > <依存関係> <groupid> com.fasterxml.jackson.core </groupid> </artifactid> </> </> </> </birgnes <Dependency> GroupId> com.fasterxml.jackson.core </groupid> <artifactid> jackson-annotations </artifactid> <version> 2.5.4 </version> </dependency> <seplency> <ependency> <emprofency> eprofency> eprofency </dependency> <! - jsr303背景検証冬眠バリデーター - > <依存関係> <groupid> org.hibernate </groupid> <artifactid> hibernate-validator </artifactid> <バージョン> 5.1.1.1.1.1.1.1.1.1.1.1.1.1.1.1.1.1.1.1.1.1.1.1.1.1.1.1.1.1.1.1.1.1.1.1.1.1.1.1.1.1.1.1.1.1.1.1. <artifactid> commons-io </artifactid> <バージョン> 2.4 </version> </dependency> <dependency> <groupid> commons-fileupload> commons-fileupload </artifactid> <バージョン> 1.3.1 </バージョン> </依存> < <artifactid> commons-lang3 </artifactid> <バージョン> 3.3.2 </version> </dependency> <! - 暗号化アルゴリズムに関連するコーデック - > <依存関係> commons-codec </groupid> <artifactid> commons-codec </artifactid> <バージョン - > <! - Oracleデータベースドライバー - > <依存関係> groupId> com.oracle </groupid> <artifactid> ojdbc6 </artifactid> <バージョン> 12.1.0.2.0 </version> </depency> <! - mysqlデータベースドライバー(ここでは使用していません) - <artifactid> mysql-connector-java </artifactid> <version> 5.0.8 </version> <scope> runtime </scope> </dependency> - > <! - proxool接続プール - > <依存> <依存> </dependency> <dependency> groupid> com.cloudhopper.proxool </groupid> <artifactid> proxool-cglib </artifactid> <バージョン> 0.9.1 </version> </dependency> <! - mybatisが必要とするjarパッケージの紹介 - > <> <依存関係> <グループ</groupid> <artifactid> mybatis </artifactid> <version> 3.3.1 </version> </dependency> <dependency> groupid> org.mybatis </groupid> <artifactid> mybatis-spring </artifactid> <バージョン> 1.2.4 </バージョン> </依存関係> < <GroupId> com.github.pagehelper </groupid> <artifactid> pagehelper </artifactid> <version> 4.2.1 </version> </dependency> </dependencies> <burtion> <bultin> <plubin> <artifactid> maven-compiler-plugin </artifactid> <fortes> </configuration> </plugin> <plagin> <artifactid> maven-war-plugin </artifactid> <version> 2.4 </version> <configuration> 3.0 </version> </configuration> </plugins> <finalname> maven_ssm </finalname> </bultion
POM.xmlを使用してOracle DriverパッケージをインポートするMavenプロジェクトに関する質問を次に示します。
Oracle認可の問題により、MavenはOracle JDBCドライバーを提供していません。 MavenプロジェクトでOracle JDBCドライバーを適用するには、ローカルリポジトリに手動で追加する必要があります。
Oracleデータベースが既にコンピューターにインストールされている場合、インストールパスの下にデータベースドライバーがあり、直接使用できます。 d:/oracle/oraclexe/app/oracle/product/10.2.0/server/jdbc/lib
OracleデータベースドライバーをOracle公式Webサイトから直接ダウンロードして、SQLステートメントを使用してデータベースドライバーのバージョンを照会することもできます。
次に、バージョンのダウンロードを確認してください:http://www.oracle.com/technetwork/database/features/jdbc/default-2280470.html
Windowsのコマンドラインインターフェイスを開き、ドライバーパッケージojdbc6のディレクトリを入力してから実行します。
MVNインストール:install -file -dgroupid = com.oracle -dartifactid = ojdbc6 -dversion = 12.1.0.2.0 -dpackaging = jar -dfile = ojdbc6.jar
「成功を構築する」が正常に表示されると、Maven Localリポジトリが自動的にインポートされます。
次に、Mavenプロジェクトに依存関係を追加できます。各座標は、次のように上記のコマンドの要素に対応します。
<Dependency> GroupId> com.Oracle </groupId> <Artifactid> ojdbc6 </artifactid> <version> 12.1.0.2.0 </version> </dependency>
Springの構成ファイル:ApplicationContext.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:aop = "http://www.springframework.org/schema/aop" xmlns:context = "http://www.springframework.org/schema/tx" xmlns:util = " XMLNS:P = "http://www.springframework.org/schema/p" xsi:schemalocation = "http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-3.0.xsd http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-3.0.xsd http://www.springframework/schema/context http://www.springframework.org/schema/context/spring-context-3.0.xsd http://www.springframework.org/schema/util http://www.springframework.org/schema/spr-構成パッケージスキャン - > <コンテキスト:Component-Scanベースパッケージ= "com.krry"> < /context:component-scan> <! - 外部リソースファイルのインポート - > <! - <コンテキスト:プロパティプレイスホルダーlocation = "classpath:jdbc.properties" /> - > - > <bean p:location = "classpath =" file、uppterties Proxool Connection Pool-> <Bean Id = "DataSource"> <! - ドライバー名、mysql - > <プロパティ名= "ドライバー" value = "$ {db.driver}"> </property> <! - このurl接続文字列は、ユーザー名とパスワードを決定する必要があります - > <ドライバー名= "$ {db.urll使用されていませんが、除外することはできません) - > <プロパティ名= "user" value = "$ {db.username}"> </property> <! - password(proxoolは使用されていませんが、除外できません) - > <プロパティ名= "$ {db.Password}偵察が完了したら、すぐにリサイクルします。タイムアウトの破壊は4秒に設定されます) - > <プロパティ名= "housekeepingsleeptime" value = "3000"> </property> <! - 接続が壊れているかどうかを自動的に確認します - > <プロパティ名= "testbeforeuse" value = "true"> </property> <! - アイドルデータベース接続が見つかります。この声明は非常に迅速に実行されるのが最適です。定義されていない場合、テストプロセスは無視されます - > <プロパティ名= "housekeepingtestsql" value = "select count(1)from dual"> </property> <! - スレッドのアクティビティ時間がこの値よりも大きいことを検出した場合。それはスレッドを殺します。サーバーの帯域幅を確認してください。次に、適切な値を設定します。デフォルトは5分です。ここに10秒を設定します - > <プロパティ名= "Maximumactivetime" value = "10000"> </property> <! - 維持するアイドル接続の最小数(現在セット20) - > <プロパティ名= "prototypecount" value = "20"> </property> <! - 最大数の接続数(現在セット100) - > (現在50を設定します) - > <プロパティ名= "motimconnectioncount" value = "50"> </property> <! - trueの場合、実行された各SQLステートメントは実行期間中に記録されます(デバッグレベル)。 ConnectionListener(Proxoolfacadeを参照)を登録して、この情報を取得することもできます。 - > <プロパティname = "trace" value = "false"> </property name = "verbose" value = "true"> </property> </bean> <! - 登録トランザクションマネージャー - > <bean id = "txmgr"> <プロパティ名= "dataSource" ref = "dataSource"> </bean> Transaction-Manager = "Txmgr"/> <! - mybatis 'sqlsessionfactory-> <bean id = "sqlsessionfactory"> <プロパティ名= "dataSource" ref = "dataSource"> </property name> <property name = "configlocation" value = "classpath:classpath"> <マッパー全体をスキャンすることができます - > <bean> <! - 複数のレポートがある場合は、コンマで分離します - > <プロパティ名= "basepackage" value = "com.krry.mapper"> </property名= " Spring MVC構成ファイル:SpringMVC.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:p = "http://www.springframework.org/schema/p" xmlns:context = "http://www.springframework.org/schema/util" xmlns:MVC = " xsi:schemalocation = "http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd http://www. http://www.springframework.org/schema/util http://www.springframework.org/schema/util/spring-util-3.0.xsd http://www.springframework.org/schema/mvc. http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc.xsd "> <! - アノテーションモードドライバーをオンにする - > <bean/> <! formattingConversionserviceFactoryBean - > <MVC:annotation-driven> <MVC:message-converters Register-Defaults = "true"> <bean> <Property name = "supportedmediatypes"> <balue> text/text/text/plain; charset = utf-8 </value> <value> html; charset = utf-8 </</<> <bean /> <bean /> <bean> <bean> <bean name = "precixjson" value = "false" /> <objectmapper "> <bean> <! - 応答ボディの日付タイプを処理 - > <プロパティname =" dateformat "> <bean> <construction-arg type =" </bean> </property> <! - フィールドがnullの場合に表示されません - > <プロパティ名= "serializationinclusion"> <value type = "com.fasterxml.jackson.annotation.jsoninclude.include" <value> application; charset = utf-8 </value> <value> application/x-www-form-urlencoded; charset = utf-8 </value> </list> </property> </bean> </mvc:message-converters> </mvc:annotation-driven> < base-package = "com.krry.controller"> </context:component-scan> <! - springmvc構成では、すべてのリクエスト(.do、adduser、JS/image/css)は、springmvcによってすべてのリクエスト(。 <! - <MVC:デフォルトセルバーハンドラー//> - > <MVC:リソースマッピング= "/Resourse/**"/** "/Resourse/"/> <! - インターセプター定義 - > <MVC:MVC:MVC:インターセプター> <! path = "/admin/**"> </mvc:マッピング> <! - これはインターセプターに入らないパスです - > <mvc:除外path = "/resourse/**"/> <! - インターセプターが入力するクラスは、入力が入力されないことを示して虚偽を返します - > <パーサー - > <bean id = "multipartresolver" p:defaultencoding = "utf-8"> <プロパティ名= "uploadtempdir" value = "/temp"> </property name = "maxuploadsize"> <値> 209715200 </value> < <value> 4096 </value> <! - 4kbサイズ読み取りと書き込み - > </プロパティ> </bean> </Bean> < </豆>
データベース構成ファイル:jdbc.properties
db.driver = oracle.jdbc.oracledriver db.url = jdbc:oracle:thin:@127.0.0.1:1521:orcl db.username = 4m+la23kca4 = db.password = wwijciympau/=
ここで暗号化アルゴリズムを使用しました
ログ構成ファイル:log4j.Properties
log4j.rootlogger = debug、console、filelog4j.appender.console = org.apache.log4j.consoleappenderlog4j.appender.console.layout = org.apache.log4j.patternlayoutlog4j.appender.console.layout.convert.converntionpittern = d HH:mm:ss} %-5p [%t] %10l - %m%nlog4j.appender.FILE=org.apache.log4j.RollingFileAppenderlog4j.appender.FILE.File=D:/logs/log4j.loglog4j.appender.FILE.MaxFileSize=1MBlog4j.appender.FILE.Append = truelog4j.appender.file.layout = org.apache.log4j.patternlayoutlog4j.appender.file.layout.conversionpattern =%d {yyyy/mm/dd/hh:mm:ss}%-5p [%t]%10L -%m%n mybatis構成ファイル:mybatis-config.xml
<?xml version = "1.0" encoding = "utf-8"?> <!doctype構成public " - // mybatis.org//dtd config 3.0 // en" "http://mybatis.org/dtd/mybatis-3-config.dtd" name = "cacheenabled" value = "true" /> <! - パフォーマンスのために関連するオブジェクトのインスタントロードをオフにします - > <name = "lazyloadingEnabled" value = "true" /> <! - 関連するオブジェクトのロードの形式を設定します。ここにオンデマンドの負荷フィールドがあります(負荷フィールドはSQLで指定されています)。関連するテーブルのすべてのフィールドは、パフォーマンスを改善するためにロードされません - > <設定名= "aggressivelazyloading" value = "false" /> <! - 不明なsqlクエリの場合、共通の効果を達成するために異なる結果セットを返すことができます - > <設定name = "MultipleresultsetsEnabled" value = "true" /> < value = "true" /> <! - カスタムプライマリキー値(プログラムによって生成されたUUID 32ビットエンコーディングなどのキー値として使用)を使用します。また、データテーブルのPK生成戦略は上書きされます - > <name = "usegeneratedkeys" value = "true" /> <! - full-aTtribute mapping " /" /" /" /">"> ottribute support ">" /> < <! - パフォーマンスを改善するバッチ更新操作のSQLをキャッシュする - > <name = "defaultexecutortype" value = "batch" /> <! - データベースが25,000秒以上応答しなかった場合 - > <> <"defaultstatementtimeout" value = "25" /> <設定nam </settings> <typealias> <! - カスタムユーザーオブジェクトのエイリアス - > <! - <typealias type = "com.krry.mybatis.sysmanage.user" airas = "user"/> - > <! - バッチ定義エイリアス - > <パッケージname = "com.krry.entity
ネットワークプログラム構成ファイル:web.xml
<?xml version = "1.0" encoding = "utf-8"?> <web-app xmlns:xsi = "http://www.w3.org/2001/xmlschema-instance" xmlns = "http://xmlns.jcp.org/xml/ns/javaee xsi:schemalocation = "http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/ns/javaee id = "webapp_id" version = "3.1"> <display-name> maven_ssm </display-name> <welcome-file-list> <welcome-file> index </welcome-file> </welcome-file-list> <! - loading spring ioc container-> <context-param> <param> <param-name> <param-value> classPath:ApplicationContext.xml </param-value> </context-param> <! - spring contextリスナー - > <リスナー> <リスナークラス> org.springframework.web.context.contextloaderlistener </ristener-class> < <リスナークラス> org.springframework.web.util.introspectorcleanuplistener </ristener-class> </ristener> <filter> <filter-name>エンコーディング</filter-name> <filter-class> org.springframework.web.filter.characterencodingfilter </フィルター< <param-name> encoding </param-name> <param-value> utf-8 </param-value> </init-param> </filter> <filter-mapping> <filter-name> ending </filter-name> <url-pattern>/*</url-pattern> </filter-mapping> <servlet-name> maven_ssm </servlet-name> <servlet-class> org.springframework.web.servlet.dispatcherservlet </servlet-class> <! - springmvc構成ファイル - > <! - 次のオプションが構成されていない場合、システムはデフォルトです。 springmvc01-servlet.xml-> <init-param> <param-name> contextconfiglocation </param-name> <param-value> classpath:springmvc.xml </param-value> </init-param> </servet < / servlet-mapping> <! - 一致することができます *.do、 *.action(理解) /(key):すべてのリクエストはSpring MVCによって解析されますが、静的リソースファイルはフィルタリングしてリリースする必要があります。この方法を使用することをお勧めします/*:> <servlet-mapping> <servet-name> maven_ssm </servlet-name> <url-pattern>/</url-pattern> </servlet-mapping> </web-app>
この時点で、基本的な構成が完了し、JARパッケージは自動的に依存しています。後続のJavaコードをテストして書き込みます
上記はこの記事のすべての内容です。みんなの学習に役立つことを願っています。誰もがwulin.comをもっとサポートすることを願っています。