AppFuse3.5 connects to the oracle database, and appfuse3.5oracle

Source: Internet
Author: User

AppFuse3.5 connects to the oracle database, and appfuse3.5oracle

AppFuse is an integrated framework for developing web application systems using Java. The biggest headache for java developers is that they do not know how to choose a large number of frameworks. The performance and compatibility of these frameworks must be filtered and compared. Appfuse author Matt Raible has made in-depth research on these frameworks and integrated the best parts of these frameworks to form the best integration framework. The latest stable version of this framework is 3.5.

Basic Framework in AppFuse:

  • Bootstrap and jQuery
  • Maven, Hibernate, Spring, and Spring Security
  • Java 7, Annotations, JSP 2.1, Servlet 3.0
  • Web Framework: GWT, JSF, Struts 2, Spring MVC, Tapestry 5, Wicket
  • JPA

AppFuse provides many out-of-the-box functions required by applications, including:

  • Verification and authorization
  • User Management
  • Remember me (Save the logon information and do not log on every time)
  • Password prompt
  • Registration and Registration
  • SSL Switching
  • Email
  • Extension-less URLs (I don't know how to translate it, for help !!!)
  • File Upload
  • Generate CRUD backend
  • Fully supports Eclipse, IDEA, and NetBeans
  • Use Maven, Jetty, and other plug-ins for Quick Start and deployment
  • Use the multi-mode option (profiles) of Cargo and Maven to support deployment of a variety of foreground applications and databases, and perform the test.

The latest AppFuse is closely related to Maven. Almost all operations are performed through Maven. Therefore, you must have a certain understanding of Maven and modular development, and have a deep understanding of Maven profiles, you also need to understand the Maven repository structure.

AppFuse supports multiple databases (Derby, H2, HSQLDB, MySQL, Oracle, PostgreSQL, and SQL Server). The default database is MySQL. When I switched to the Oracle database, I found a problem and found this article. The following describes the problems and solutions.

1. First download and install Maven 3.1.0 +. There are many tutorials on the Internet, so I will not go into details here. Of course, you also need JDK 7 + and MySQL 5.5 +.

2. Use Maven to generate an empty project that contains the AppFuse framework:

Mvn archetype: generate-B-DarchetypeGroupId = org. appfuse. archetypes-DarchetypeArtifactId = appfuse-modular-spring-archetype-DarchetypeVersion = 3.5.0-DgroupId = com. myCompany. myProject-DartifactId = myProject-DarchetypeRepository = https://oss.sonatype.org/content/repositories/appfuse

This is a command for generating (archetype: generate) Framework Code of mvn and will be used later. MyCompany is the company name and myProject is the project name. The AppFuse version is 3.5.0. The most important part is appfuse-modular-spring-archetype. modular represents multiple modules, and spring represents spring MVC as the framework in the previous section.

Start command line (cmd ). Modify the current directory to the Java workspace (the directory where you want to place the Code ). Enter a string of characters starting with mvn and press Enter. Due to the well-known reasons of tianchao and the exit of Google, some jar packages may not be able to find the source, and you may have to FQ (FreeGate) to complete this command. Or, because the network speed is too slow and the download times out, you need to try the above command repeatedly.

In short, hard work is required, and some unconventional means are required...

The magic thing happened. You found that there is a folder in your workspace.

Don't worry. You need a few more steps.

3. Download the source code and template used in the framework.

Mvn appfuse: full-source

At this time, if the system runtime environment JDK and database MySql (the root password is empty) are ready, you can run the command mvn jetty: run in the web directory to deploy the startup project and log on to http: // localhost: 8080 has accessed your project!

4. Generate a project file.

Switch the current directory of the command line to the myproject directory. If you are using eclipse, you can run: mvn eclipse: eclipse command. If you are using idea, run: mvn idea: idea. Project files and related dependencies are generated.

5. Switch to the Oracle database.

AppFuse provides multiple database options (profiles) for us ). To view these profiles, type the following command:

Mvn help: full-profiles

Show all available profiles.

Mvn help: active-profiles

Displays activated profiles.

 

This is simple. You only need to execute the following command to switch to oracle.

Mvn clean install-P oracle

Clear the files generated by the project and install the oracle Profile.

However, three errors were reported during the execution, resulting in execution failure.

Problem 1: the odbc jar package cannot be found.

Go to the Maven repository and find the oracle repository C: \ Users \ [localUser] \. m2 \ repository \ com \ oracle \ ojdbc14 \ 10.2.0.2.0. This repository is generated by AppFuse, but the Jar package is missing below. We need to download an ojdbc14-. jar corresponding to 10.2.0.2.0 from the Oracle website to put it under this directory and rename it: ojdbc14-10.2.0.2.0.jar.

Some people think that the oracle version is now 12, and the 10 driver is still used, which is a little outdated. You can install your own oracle database. The method is to download the corresponding oracle jar and execute the maven command to install the jdbc dependency. I just installed the oracle database 11.2 GB and used its driver to save download.

Mvn install: install-file-Dfile = C: \ app/[localUser]/product/11.2.0/dbhome_1/jdbc/lib/ojdbc6_g.jar-DgroupId = com. oracle-DartifactId = ojdbc6-Dversion = 11.2.0-Dpackaging = jar

If you do not have Oracle installed on your local machine or the global database name is not XE, you may need to modify the default database connection option. Open File: C: \ Users \ [localUser] \. m2 \ repository \ org \ appfuse \ 3.5.0 \ appfuse-3.5.0.pom. Back up data. Find the oracle-related profile and change it to the following:

        <profile>            <id>oracle</id>            <properties>                <dbunit.dataTypeFactoryName>org.dbunit.ext.oracle.OracleDataTypeFactory</dbunit.dataTypeFactoryName>                <dbunit.schema>MYPROJECT</dbunit.schema>                <!-- Make sure to capitalize the schema name -->                <!--<dbunit.operation.type>CLEAN_INSERT</dbunit.operation.type>-->                

Myproject is the database that I created specifically for this project. The global Instance name of the local database is orcl. Jdbc is also changed to 11.2. Some changes will be mentioned later.

Problem 2: The database script cannot be executed. Go to the myproject \ core \ target directory and find schema. SQL. Open it and check that everything is normal. There is no problem if you execute this SQL file under sqlplus.

The reason for file execution is that this SQL statement is not executed by sqlplus, but is executed by hibernate! When hibernate executes an SQL statement, there cannot be a paragraph ending with ";". So an error is reported! The solution is to add a setting in the oracle profile in the appfuse-3.5.0.pom to set the paragraph delimiter to NULL:

<Hibernate. export. schema. delimiter>

The problem is solved!

Problem 3: The unit test fails. A strange error is reported:

Tests run: 9, Failures: 0, Errors: 1, Skipped: 0, Time elapsed: 2.167 sec <FAILURE!
TestUpdateUser (com. exam. dao. UserDaoTest) Time elapsed: 0.088 sec <ERROR!
Java. lang. Exception: Unexpected exception, expected <org. springframework. dao. DataIntegrityViolationException> but was <org. springframework. orm. hibernate4.HibernateSystemException>

This problem has been submitted to the AppFuse email list, but there is no positive response, there is only one way to circumvent it. For deep-seated reasons, you must be able to continue mining!

The solution is to comment out row 68th of the test code UserDaoTest. java: // user2.setRoles (user. getRoles ());

        user2.setLastName(user.getLastName());        user2.setPassword(user.getPassword());        user2.setPasswordHint(user.getPasswordHint());        //user2.setRoles(user.getRoles());        user2.setUsername(user.getUsername());        user2.setWebsite(user.getWebsite());

After these problems are modified, the oracle profile is activated successfully. The test passes and the jar package and war package are generated.

 

In addition, the way I modify the oracle database profile (appfuse-3.5.0.pom) is not desirable, the more scientific way is to modify the pom. xml.

<Properties>
... Other settings
<! -- Added the following settings for the connected oracle database. The default values of these settings point to the mysql database --> <dbunit. dataTypeFactoryName> org. dbunit. ext. oracle. oracleDataTypeFactory </dbunit. dataTypeFactoryName> <dbunit. schema> MYPROJECT </dbunit. schema>

 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.