找不到针对Js和css的HTTP请求的映射,我不了解jsp文件,不知道为什么,因为过去的代码没问题,因为我向其中添加了AppConfig然后发生了。我是新的春季MVC,不知道如何解决它,XML没问题,因为我正在测试另一个项目,但是在添加config.java然后erorr
spring-web-config.xml
<context:component-scan base-package="org.planning.net" />
<context:component-scan base-package="org.planning.net.controllers" annotation-config="true"/>
<context:component-scan base-package="org.planning.net.service" annotation-config="true"/>
<context:component-scan base-package="org.planning.net.logic" annotation-config="true"/>
<context:component-scan base-package="org.planning.net.dao" annotation-config="true"/>
<bean
class="org.springframework.web.servlet.view.InternalResourceViewResolver">
<property name="prefix">
<value>/WEB-INF/pages/</value>
</property>
<property name="suffix">
<value>.jsp</value>
</property>
</bean>
<mvc:resources mapping="/resources/**" location="/resources/"/>
<!-- Spring Component -->
<context:annotation-config />
<mvc:default-servlet-handler/>
</beans>
web.xml
<?xml version="1.0" encoding="UTF-8"?>
<element>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns="http://java.sun.com/xml/ns/javaee"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee
http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd"
id="WebApp_ID" version="3.1">
<display-name>Net</display-name>
<!-- For web context -->
<servlet>
<servlet-name>dispatcher</servlet-name>
<servlet-class>
org.springframework.web.servlet.DispatcherServlet
</servlet-class>
<init-param>
<param-name>contextConfigLocation</param-name>
<param-value>/WEB-INF/spring-web-config.xml</param-value>
</init-param>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>dispatcher</servlet-name>
<url-pattern>/</url-pattern>
</servlet-mapping>
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>/WEB-INF/spring-web-config.xml</param-value>
</context-param>
<listener>
<listener-class>
org.springframework.web.context.ContextLoaderListener
</listener-class>
</listener>
<!-- For root context -->
<!--
<listener>
<listener-class>
org.springframework.web.context.ContextLoaderListener
</listener-class>
</listener>
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>/WEB-INF/spring-core-config.xml</param-value>
</context-param>
-->
</web-app>
</element>
AppConfig.java
@SingletonConfig
@Configuration
@Component
@EnableWebMvc
@ImportResource({"classpath:get-bean-name.xml"})
public class AppConfig implements Config {
private static final AppConfig INSTANCE = new AppConfig();
private Dialect dialect;
private LocalTransactionDataSource dataSource;
private TransactionManager transactionManager;
private AppConfig() {
dialect = new MysqlDialect();
dataSource = new LocalTransactionDataSource("jdbc:jtds:sqlserver://localhost:1433/NetDatabase;instance=SQLEXPRESS", "ccc", "1");
transactionManager = new LocalTransactionManager(dataSource.getLocalTransaction(getJdbcLogger()));
}
@Override
public Dialect getDialect() {
return dialect;
}
public DataSource getDataSource() {
return dataSource;
}
public TransactionManager getTransactionManager() {
return transactionManager;
}
public static AppConfig singleton() {
return INSTANCE;
}
@Override
public int getBatchSize() {
// TODO Auto-generated method stub
return 0;
}
@Override
public ClassHelper getClassHelper() {
// TODO Auto-generated method stub
return null;
}
@Override
public String getDataSourceName() {
// TODO Auto-generated method stub
return null;
}
@Override
public ExceptionSqlLogType getExceptionSqlLogType() {
// TODO Auto-generated method stub
return null;
}
@Override
public int getFetchSize() {
// TODO Auto-generated method stub
return 0;
}
@Override
public JdbcLogger getJdbcLogger() {
// TODO Auto-generated method stub
return new Slf4jJdbcLogger();
}
@Override
public int getMaxRows() {
// TODO Auto-generated method stub
return 0;
}
@Override
public int getQueryTimeout() {
// TODO Auto-generated method stub
return 0;
}
@Override
public RequiresNewController getRequiresNewController() {
// TODO Auto-generated method stub
return null;
}
@Override
public SqlFileRepository getSqlFileRepository() {
// TODO Auto-generated method stub
return null;
}
@Override
public boolean ignoreUnknownColumn() {
// TODO Auto-generated method stub
return false;
}
}
答案 0 :(得分:0)
我发现我的AppConfig是错误的,我将其更改为,并且运行良好。但是另一个问题是我无法使用mysql Sever 2014连接数据库,URL:“ jdbc:sqlserver:// localhost:1433; databaseName = NetDatabase”,并且为此设置了用户名和密码。问题:[DOMA2048] saidクションを取得しようとしましたが失败しました。トランザクションが开始されていません。说不能连接数据库
datasource-cfg.properties
jdbc.sqlServer.driver =com.microsoft.sqlserver.jdbc.SQLServerDriver
jdbc.sqlServer.url =jdbc:sqlserver://localhost:1433
jdbc.sqlServer.databaseName =NetDatabase
jdbc.sqlServer.user =ccc
jdbc.sqlServer.password =1
AppConfig
public class AppConfig extends DomaAbstractConfig {
private static final String JDBC_FILE = "datasource-cfg.properties";
private static final String URL = "jdbc.sqlServer.url";
private static final String USER = "jdbc.sqlServer.user";
private static final String PASSWORD = "jdbc.sqlServer.password";
private static final String DATABASE_NAME = "jdbc.sqlServer.databaseName";
static {
try {
Class.forName("com.microsoft.sqlserver.jdbc.SQLServerDriver");
} catch (ClassNotFoundException e) {
throw new RuntimeException(e);
}
}
protected static final LocalTransactionalDataSource dataSource = createDataSource();
protected static final Dialect dialect = new MssqlDialect();
@Override
public DataSource getDataSource() {
return dataSource;
}
@Override
public Dialect getDialect() {
return dialect;
}
protected static LocalTransactionalDataSource createDataSource() {
Properties prop = new Properties();
try {
prop.load(ClassName.class.getClassLoader().getResourceAsStream(JDBC_FILE));
} catch (IOException e) {
e.printStackTrace();
}
String url = prop.getProperty(URL);
String user = prop.getProperty(USER);
String password = prop.getProperty(PASSWORD);
String databaseName = prop.getProperty(DATABASE_NAME);
String connection = url + ";" + "databaseName=" + databaseName;
SimpleDataSource dataSource = new SimpleDataSource();
dataSource.setUrl(connection);
dataSource.setUser(user);
dataSource.setPassword(password);
return new LocalTransactionalDataSource(dataSource);
}
public static LocalTransaction getLocalTransaction() {
return dataSource.getLocalTransaction(defaultJdbcLogger);
}
}